Why is VK_Control + VKHome not working for me?

procedure TSell.ApplicationEvents1Message(var Msg: tagMSG; var Handled: Boolean); begin if (Msg.Message=WM_KEYDOWN)and(Msg.wParam=VK_CONTROL+VK_HOME)then begin end; 
+4
source share
2 answers

To check the status of the VK_CONTROL virtual key, you must use the GetKeyState function.

try this sample

 procedure TSell.ApplicationEvents1Message(var Msg: tagMSG; var Handled: Boolean); begin if (Msg.Message=WM_KEYDOWN) then if (GetKeyState(VK_CONTROL) < 0) and (Msg.wParam=VK_HOME) then //do your stuff end; 
+10
source

VK_CONTROL + VK_HOME = 17 + 36 = 53 = Ord('5') . You check to see if user pressed 5 on the top line of the keyboard. (Not what you wanted? Your question didn't say.)

You cannot just add virtual key codes from two independent keys to find out both of them are pressed at the same time. Ctrl and Home are two different keys, each of which generates its own messages wm_KeyDown and wm_KeyUp . (But do not try to detect both of these keys in the sequence. It will be much more complicated than you want. Determine when the Home button is pressed, and then use GetKeyState , as Roose's answer shows, to determine if Ctrl was already unavailable at the time You have received the current keyboard message.)

+7
source

All Articles