Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

RegisterHotKey

94 views
Skip to first unread message

Mhaxx

unread,
Jul 23, 2009, 7:01:49 AM7/23/09
to
Could someone give me an example how to call RegisterHotKey and moreover
then how to catch the button pressed?

Massimo


Paul G. Tobey [eMVP]

unread,
Jul 23, 2009, 11:35:27 AM7/23/09
to
The help is all you should need. There are no mysteries. The help tells you
that you pass a window handle and that the window that you specify will
receive WM_HOTKEY messages when the key is pressed (look up WM_HOTKEY for
details). I would think that the identifier parameter is clear. The
modifiers indicate more about the key and the vk parameter is the virtual
key code for the key itself. Of course, this is something like VK_F1. For
letters and numbers, it's just the ASCII code of the letter or number.

If there's something you're not telling us about why you're finding this
difficult, you need to clarify. The call itself is dead simple...

Paul T.

"Mhaxx" <super...@despammed.com> wrote in message
news:OWQqsS4C...@TK2MSFTNGP03.phx.gbl...

Mhaxx

unread,
Jul 24, 2009, 3:59:38 AM7/24/09
to
> The help is all you should need. There are no mysteries. The help tells
you

That's what I do:

RegisterHotKey(hWnd, VK_F6, MOD_KEYUP, VK_F6);

...

while (GetMessage(&msg, NULL, 0, 0))
{
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
if (msg.message == WM_HOTKEY)
{
if (msg.wParam == VK_F6)
{
...
}
}
}
}

But I get 6 times VK_F6 after 1 time I pressed that button: why?

Massimo


Rik Attrill

unread,
Jul 24, 2009, 7:04:15 AM7/24/09
to
Hi,

Just a quick thought - is your message handling function is returning
TRUE to indicate the message is being handled?

best regards,
Rik A

Mhaxx

unread,
Jul 24, 2009, 9:49:05 AM7/24/09
to
> Just a quick thought - is your message handling function is returning
> TRUE to indicate the message is being handled?

Do you refer to RegisterHotKey or GetMessage?

Massimo


Mhaxx

unread,
Jul 24, 2009, 9:49:26 AM7/24/09
to
> Just a quick thought - is your message handling function is returning
> TRUE to indicate the message is being handled?

Do you refer to RegisterHotKey or GetMessage?

Massimo


Rik Attrill

unread,
Jul 24, 2009, 11:35:49 AM7/24/09
to
> Do you refer to RegisterHotKey or GetMessage?

I was referring to your windows callback function - although I can see
from your code example that you may not have one in this case.

What I was getting at is that some message require a return value to
indicate if they have been handled or not - e.g. WM_KEYDOWN:
http://msdn.microsoft.com/en-us/library/aa921842.asp

On closer inspection, though, WM_HOTKEY does not have this
requirement.

regards,
Rik


Paul G. Tobey [eMVP]

unread,
Jul 27, 2009, 12:27:48 PM7/27/09
to
Why are you setting the ID to the virtual key code for the key? That seems
like a bad idea or at least somewhat confusing for future users of your
code. Generally, you'd want to use an ID. In your application, this ID
might correspond to an action (hotkey #1, whose ID is 1000, causes the
screen display to zoom in). Then you can assign any convenient key to that
action and you don't have to change both the RegisterHotKey() call AND the
message loop to make the change (this isolates the value of the key from the
hot key action).

You read the help on the RegisterHotKey() function? You see that passing
MOD_KEYUP will send you a message on both key down and key up events. If
the key is held down for any length of time, of course, you'll get key
repeat, just like on any other key. I'd bet that a little bit of thinking
about it would tell you why you're seeing the message six times...You also
have Remote Spy that will show you the messages that are sent.

Paul T.

"Mhaxx" <super...@despammed.com> wrote in message

news:%23oGg$SDDKH...@TK2MSFTNGP04.phx.gbl...

0 new messages