2

What are RegisterHotKeys and global keyboard hooks, and how do they work?

I want to make a key to get focused on my application's Form (when it's minimized) and then focus on a textbox, so from what I've read I need to use the RegisterHotKeys function (that's a better solution for my needs), but i couldn't find how or where I can choose my own key (only one key - ESC) and then command it to focus on my form, and then on the textbox.

Ry-
  • 218,210
  • 55
  • 464
  • 476
Mazki516
  • 997
  • 1
  • 10
  • 20

1 Answers1

1

Sample on how to use hot keys.

class myform : Form
{
    public myform()
    {
        RegisterHotKey(Handle, id, modifiers, mykey);
    }
    protected override void WndProc(ref Message m)
    {
        if (m.Msg == 0x312) // this is WM_HOTKEY
        {
            Show();
        }
        base.WndProc(ref m);
    }
}
Andrew Keith
  • 7,515
  • 1
  • 25
  • 41
  • Thanks a lot! btw what key is 0X312 ? Thanks! Amit – Mazki516 Oct 14 '09 at 02:36
  • 0x312 is not a key, its the WM_HOTKEY message. the key is the virtual key codes which you register with RegisterHotKey. http://msdn.microsoft.com/en-us/library/ms927178.aspx – Andrew Keith Oct 14 '09 at 02:54
  • Andrew hi, thank you very much. but, i didn't "got there yet", RegisterHoyKey(Handle, id???, modifiers, mykey??) I've a barcode reader, i configured it to "press" the ESC key, then send the barcode and then "press" enter. i want my program to identify the ESC "Press" and then show the form and then focused on a textbox(these two commands i know how to do it), there is a way to register a hoy key without a modifier(Null is good?) you gave me that great page, but i don't know what to write in id and in mykey, the function ask for int(uint?) Thanks a lot in advance!! Amit – Mazki516 Oct 14 '09 at 21:58