first, sorry my english! hi guys, i want to make something when i press the "x" then "ax" this is code -----------------
#include "stdafx.h"
using namespace std;
HHOOK hKBHook;
UINT TimerId;
UINT TimerId1;
VOID CALLBACK DelayX(HWND hWnd, UINT nMsg, UINT nIDEvent, DWORD dwTime) {
keybd_event(65, 0, WM_KEYDOWN, 0);
keybd_event(65, 0, WM_KEYUP, 0);
keybd_event(88, 0, WM_KEYDOWN, 0);
keybd_event(88, 0, WM_KEYUP, 0);
KillTimer(NULL, TimerId);
}
VOID CALLBACK XSPlay(HWND hWnd, UINT nMsg, UINT nIDEvent, DWORD dwTime) {
PlaySound(TEXT("tocks.wav"), NULL, SND_ASYNC);
KillTimer(NULL, TimerId1);
}
LRESULT CALLBACK KeyboardProc(int nCode, WPARAM wParam, LPARAM lParam)
{
if (wParam == WM_KEYDOWN)
{
PKBDLLHOOKSTRUCT pKey = (PKBDLLHOOKSTRUCT)lParam;
cout << pKey->vkCode << " ";
switch (pKey->vkCode)
{
case 88:
{
PlaySound(TEXT("tocks.wav"), NULL, SND_ASYNC);
KillTimer(NULL, TimerId1);
TimerId1 = SetTimer(NULL, 0, 297, &XSPlay);
TimerId = SetTimer(NULL, 0, 290, &DelayX);
return 1;
}
case 19:
{
UnhookWindowsHookEx(hKBHook);
return 1;
}
}
}
CallNextHookEx(hKBHook, nCode, wParam, lParam);
return 0;
}
int _tmain(int argc, _TCHAR* argv[]) {
HMODULE hInstance = GetModuleHandle(NULL);
hKBHook = SetWindowsHookEx(WH_KEYBOARD_LL, KeyboardProc, hInstance, NULL);
MSG Msg;
while (GetMessage(&Msg, NULL, 0, 0)) {DispatchMessage(&Msg);}
UnhookWindowsHookEx(hKBHook);
return 0;
}
the problem is press x -> send ax -> hooked this x too -> send ax ---------- loop and i'm really noob maybe many another codes are need improvement. give me your advise for learning C++ :) thanks for reading!
看看这个你也许可以使用额外的信息参数指定,如果这是你自己的X模拟,以防止环路
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.