Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why doesn't VK_Control+VKHome work for me?

Tags:

delphi

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;
like image 470
Saeed Robatjazi Avatar asked Dec 03 '22 08:12

Saeed Robatjazi


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;
like image 120
RRUZ Avatar answered Dec 05 '22 21:12

RRUZ


VK_CONTROL + VK_HOME = 17 + 36 = 53 = Ord('5'). You're checking whether the user has pressed 5 along the top row of the keyboard. (Isn't that what you wanted? Your question didn't say.)

You can't just add the virtual-key codes of two independent keys to discover whether they're both being pressed simultaneously. Ctrl and Home are two different keys, and each one generates its own wm_KeyDown and wm_KeyUp messages. (But don't try to detect the pressing of both those keys in sequence. It will get far more complicated than you want. Detect when Home is pressed, and then use GetKeyState, like Rruz's answer demonstrates, to detect whether Ctrl was already down at the time you received the current keyboard message.)

like image 44
Rob Kennedy Avatar answered Dec 05 '22 20:12

Rob Kennedy