Application Global hotkeys

This is a discussion on Application Global hotkeys within the Windows Programming forums, part of the Platform Specific Boards category; How do I create a C# hotkey that can be triggered in my app but won't lock other running applications ...

  1. #1
    Registered User
    Join Date
    Dec 2005
    Posts
    54

    Application Global hotkeys

    How do I create a C# hotkey that can be triggered in my app but won't lock other running applications from using that hot key?

    Is the only way to achieve this is by doing a key press check event on all the possible "focus-able" controls on my app?

  2. #2
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,246
    In general, windows only sends keypresses to the window that has the focus. I don't program in C#, but I doubt that it works differently than a regular Win32 app in that regards.

    In other words, if your application doesn't have the focus, then it won't receive keypresses, so you won't "block" other applications in any way.
    bit∙hub [bit-huhb] n. A source and destination for information.

  3. #3
    Registered User
    Join Date
    Dec 2005
    Posts
    54
    There is the RegisterHotKey command im user32.dll to register hotkeys as global, which will fire events regardless of who has focus. I put a check in which if my window did not have focus, I set the e.handled to false, however that had no effect at all.

    I don't really want events to fire when my window is not focused, but I wanted them to fire regardless of what had focus within my application. Seems putting key press events on each object may do the job.

  4. #4
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,246
    Quote Originally Posted by JeremyCAFE View Post
    There is the RegisterHotKey command im user32.dll to register hotkeys as global, which will fire events regardless of who has focus. I put a check in which if my window did not have focus, I set the e.handled to false, however that had no effect at all.

    I don't really want events to fire when my window is not focused, but I wanted them to fire regardless of what had focus within my application. Seems putting key press events on each object may do the job.
    You might want to get this issue moved to the C# forum. What you want to do is really easy with regular Win32 programming, but I don't know how to help you with the C# stuff.
    bit∙hub [bit-huhb] n. A source and destination for information.

  5. #5
    Registered User
    Join Date
    Dec 2005
    Posts
    54
    I ended up getting what I needed by setting KeyPreview to true on my main form and then catching KeyDown on that form.

    Thank you.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 0
    Last Post: 11-22-2009, 10:23 AM
  2. Global hooks problem
    By chottachatri in forum C++ Programming
    Replies: 3
    Last Post: 07-13-2009, 09:01 AM
  3. basic question about global variables
    By radeberger in forum C++ Programming
    Replies: 0
    Last Post: 04-06-2009, 12:54 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21