Home > database >  win32api.SendMessage not working when trying to release a button
win32api.SendMessage not working when trying to release a button

Time:12-05

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:

SendMessage lParam(0)
enter image description here

PostMessage lParam(0)
enter image description here

Keystroke Messages
enter image description here

INPUT inputs{};
inputs.type = INPUT_KEYBOARD;
inputs.ki.wVk = 0x41;
inputs.ki.dwFlags = KEYEVENTF_KEYUP;
UINT uSent = SendInput(1, &inputs, sizeof(INPUT));

enter image description here

Dead-Character Messages(such as The circumflex key on a German keyboard)

  1. WM_KEYDOWN
  2. WM_DEADCHAR
  3. WM_KEYUP
  4. WM_KEYDOWN
  5. WM_CHAR
  6. 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.

  • Related