Archived

This topic is now archived and is closed to further replies.

Capturing Key combinations

This topic is 5445 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Hey guys, I''ve been working on this program for a couple of weeks. I have a keyboard hook and I would like to be able to catch the key combination Ctrl+Alt+L with it. I''ve tried this by using:
KBDLLHOOKSTRUCT *hooked=(KBDLLHOOKSTRUCT *)lParam;

if ((hooked->vkCode==0x4C && hooked->flags & LLKHF_ALTDOWN) && (hooked->vkCode==VK_RCONTROL||hooked->vkCode==VK_LCONTROL))
{
SendMessage(hWndMain, HM_LPRESSED, NULL, NULL);
return 1;
}

It seems that vkCode can only have one key being pressed. How should I rephrase this, so it sends the message when Ctrl+Alt+L is pressed?

Share on other sites
simple way : USE DIRECT INPUT!!!

Share on other sites
Shouldn''t the control button be in the flags structure?

Share on other sites
I had hoped it was, but only alt is in the the struct flag.

Nevermind, I found a way. I'm using :
GetAsyncKeyState (VK_CONTROL) >> ((sizeof(SHORT) * 8) - 1);

Gives me true if ctrl is pressed, then I can just add that to the test I had above.
Thanks

[edited by - Ranthalion on July 25, 2003 2:55:26 PM]

Share on other sites
you don''t need a keyboard hook. just call RegisterHotKey for the required combination and you''ll get a WM_HOTKEY msg when the sequence is keyed. works for almost all key combinations.

Share on other sites
btw, the low-level keyboard hook does give you control key up and down events, not flags. you have to track the control key up/down sequences yourself. the virtual-key codes are VK_LCONTROL and VK_RCONTROL. the Alt key is tracked via a separate flag since it has special meaning to the system (menu activation, window manager activation, task window, etc.)

Share on other sites
I have newbie question about input; which has more overhead, directInput, or the Win32 API?

Share on other sites
I''m not sure on this, but I would think that Direct Input has more overhead. But again, I''m not sure.

I need more than just a hot key because my hook also handles Alt+Tab, the Windows buttons,and Ctrl+Esc, stuff like that. I also need to be able to capture the key sequence when my program isn''t active or showing.

Share on other sites
It didn''t work... Does anyone see any reason this would not perform appropriately?

#define KEYISDOWN(x) (GetAsyncKeyState(x) & 0x8000 ? true : false)KBDLLHOOKSTRUCT *hooked=(KBDLLHOOKSTRUCT *)lParam;if ((KEYISDOWN(VK_CONTROL) && KEYISDOWN(0x4C)) && hooked->flags & LLKHF_ALTDOWN)     MessageBox(NULL, "Ctrl+Alt+L pressed", "Buttons", MB_OK);

I''m having the hardest time just trying to be notified if Ctrl+Alt+L is pressed in my Low Level Keyboard Hook.

• 18
• 11
• 19
• 9
• 52
• Forum Statistics

• Total Topics
631397
• Total Posts
2999810
×