Multiple hotkeys [c#]

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    Multiple hotkeys [c#]

    In a windows form application, I register a hotkey to be used throughout the application. However, I would also like a second hotkey to be registered and used, but this isn't too clear as to how to accomplish.

    When the form loads, I do this (bearing in mind I have imported the DLLs previously)
    Code:
    RegisterHotKey(this.Handle, this.GetType().GetHashCode(), 2, (int)'A');
    Then I use the WndProc method to catch the hotkey. Like so,
    Code:
    protected override void WndProc(ref Message m)
            {
                if (m.Msg == 0x0312)
                    CopyToClip();
                base.WndProc(ref m);
            }
    This then runs the method CopyToClip().

    Any ideas on how I can add another hotkey?
  • Curtis Rutland
    Recognized Expert Specialist
    • Apr 2008
    • 3264

    #2
    Let me ask you this...do you need the full Hotkey functionality? Or are you already going to be focused on the form?

    If you are focused on the form, you can handle the KeyDown event, and test for several keys.

    Comment

    • tlhintoq
      Recognized Expert Specialist
      • Mar 2008
      • 3532

      #3
      Does something like this work?

      Code:
      if ((m.Msg == 0x0312) || (m.Msg == 0x314) || (m.Msg == 0x0327))
      {
           // Do your thang
      }
      base.WndProc(ref m);

      Comment

      • Markus
        Recognized Expert Expert
        • Jun 2007
        • 6092

        #4
        Originally posted by insertAlias
        Let me ask you this...do you need the full Hotkey functionality? Or are you already going to be focused on the form?

        If you are focused on the form, you can handle the KeyDown event, and test for several keys.
        No, the form doesn't have focus.

        Originally posted by tlhintoq
        Does something like this work?

        Code:
        if ((m.Msg == 0x0312) || (m.Msg == 0x314) || (m.Msg == 0x0327))
        {
             // Do your thang
        }
        base.WndProc(ref m);
        I wouldn't want the hotkeys to do the same thing, but I could seperate that into if/elses. The problem is: how do I know that CTRL + G would be 0x0323* ?

        *Guess.

        Comment

        • tlhintoq
          Recognized Expert Specialist
          • Mar 2008
          • 3532

          #5
          Originally posted by Markus
          No, the form doesn't have focus.



          I wouldn't want the hotkeys to do the same thing, but I could seperate that into if/elses. The problem is: how do I know that CTRL + G would be 0x0323* ?

          *Guess.
          Maybe the best way is to look for the Windows message of key down (0x100) then check what key(s) are pressed.
          Helpful article

          Comment

          Working...