i am trying to send some virtual keycodes to an application while it is out of focus. I get it to work without a problem except for releasing normal keys.
I have tried:
win32api.SendMessage(hwnd, win32con.WM_KEYUP, VK_CODE["a"])
win32api.PostMessage(hwnd, win32con.WM_KEYUP, VK_CODE["a"])
releasing a key works perfectly with the left mouse button:
win32api.SendMessage(hwnd, win32con.WM_LBUTTONUP, win32con.MK_LBUTTON, 0)
and using keydb_event:
win32api.keybd_event(VK_CODE[i],0 ,win32con.KEYEVENTF_KEYUP ,0)
But for some reason when trying to release a key using SendMessage it pressed down the button instead.
CodePudding user response:
INPUT inputs{};
inputs.type = INPUT_KEYBOARD;
inputs.ki.wVk = 0x41;
inputs.ki.dwFlags = KEYEVENTF_KEYUP;
UINT uSent = SendInput(1, &inputs, sizeof(INPUT));
Dead-Character Messages(such as The circumflex key on a German keyboard)
- WM_KEYDOWN
- WM_DEADCHAR
- WM_KEYUP
- WM_KEYDOWN
- WM_CHAR
- WM_KEYUP
It depends on how the application implements WM_KEYUP and then simulation is not reliable.
Attached a classic article You can't simulate keyboard input with PostMessage.
CodePudding user response:
for anyone reading this later on the problem was i wasn't specifying the Lparam in the function. this post explains it very well.
should also mention SPY which made understanding how keypresses in windows work a lot easier.