Code:
for(;;)
{
if(KEY_DOWN(VK_END)) //hotkey end
{
giveMeThatCP(5000); // What I want
while(KEY_DOWN(VK_END))
Sleep(50);
}
Sleep(100);
}
You can integrate the Sleep call into the for-loop as follows:
for(;;Sleep(100)). Makes it a little cleaner, imo.
Also this macro:
Code:
#define KEY_DOWN(vk) ((GetAsyncKeyState(vk) & 0x8000) ? true : false)
can be reduced to: (&0x8000 is superfluous)
Code:
#define KEY_DOWN(vk) (GetAsyncKeyState(vk))
This is not necessary:
Code:
while(KEY_DOWN(VK_END))
Sleep(50);
Use:
Code:
#define KEY_DOWN(vk) (GetAsyncKeyState(vk)&1)
. . . . . .
. . . . . .
if(KEY_DOWN(VK_END)) //hotkey end
giveMeThatCP(5000); // What I want
You won't need a delay here with: (result & 1).
See
[Only registered and activated users can see links. Click Here To Register...] for reference about the GetAsyncKeyState result.
Extra notes:
- Your thread does not return a value. MSDN recommends to return 0.
- You do not need to type-cast the thread procedure in the call to CreateThread.
- Inline assembler is not required to call function pointers directly.
Example cleaned up source code:
Code:
#include <Windows.h>
void GiveContributionPoint(int CP)
{
((void (__thiscall*)(void*,int))0x1A2B1A)((void*)0x01A2B8C,CP);
}
DWORD WINAPI MainThread(LPVOID lpParameter)
{
for(;;Sleep(20)) // for-body: for(exp,boolean,exp)
if(GetAsyncKeyState(VK_END)&1)
GiveContributionPoint(5000);
return 0;
}
BOOL APIENTRY DllMain(HINSTANCE hModule, DWORD ReasonForCall, LPVOID Reserved)
{
switch(ReasonForCall)
{
case DLL_PROCESS_ATTACH:
{
DWORD ThreadID;
HANDLE hThread = CreateThread(NULL, 0, MainThread, NULL, 0, &ThreadID);
}
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}