CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Aug 2006
    Posts
    83

    Question order of applications to process SystemwideHotKey?

    I wrote an application that reacts to the keypress <F9> even when it's not in the foreground by using SystemwideHotkey.

    Now I noticed this: If I run the same app TWICE it's always the app that I started last that reacts to the event: <F9>-pressed

    Question: Is there a way to change the order in which the apps react to an even?

    Is there some kind of "stack" where the top application (app1) gets the chance to react to events first, then the next application below (app2) gets the chance to react to all events NOT handled by app1 and so on until the bottom of the "stack" is reached? If so, I want to put the app that handled the first keypress of <F9> to the bottom of the stack.

    Thanks folks,
    beamer-dreamer

  2. #2
    Join Date
    Feb 2000
    Location
    OH - USA
    Posts
    1,892

    Arrow Re: order of applications to process SystemwideHotKey?

    I'm assuming that you're using [RegisterHotKey], but can you post the exact code in use?
    Good Luck,
    Craig - CRG IT Solutions - Microsoft Gold Partner

    -My posts after 08/2015 = .NET 4.x and Visual Studio 2015
    -My posts after 11/2011 = .NET 4.x and Visual Studio 2012
    -My posts after 02/2010 = .NET 4.0 and Visual Studio 2010
    -My posts after 12/2007 = .NET 3.5 and Visual Studio 2008
    -My posts after 04/2007 = .NET 3.0 and Visual Studio 2005
    -My posts before 04/2007 = .NET 1.1/2.0

    *I do not follow all threads, so if you have a secondary question, message me.

  3. #3
    Join Date
    Aug 2006
    Posts
    83

    Arrow Re: order of applications to process SystemwideHotKey?

    Basically what I'd like to know is: is there a hierarchy of the running applications when it comes to handling a raised event? Which app gets the info about a raised event FIRST; if it doesn't handle it which app gets the info SECOND etc.?

    I don't think that this is limited to HotKey, but here's the code anyway:
    Code:
    Private Sub SystemWideHotKeyComponentF9_HotkeyPressed(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SystemWideHotkeyF9.HotkeyPressed
    Display.Text="<F9> pressed!"
    End Sub

  4. #4
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,283

    Re: order of applications to process SystemwideHotKey?

    Well, if you're running the same app multiple times, this is what I'd do :

    I'd set up a counter and add that particular counter to the Window's titlebar, by doing that, I'll have something like this :
    Code:
    Application 1
    Application 2
    etc.
    By doing this, it will be easy to use FindWindow API to get the text of the particular window you want to bring to front, and use SetForegroundWindow API to bring it to the front.

    Does that sound like a plan to you ¿

  5. #5
    Join Date
    Aug 2006
    Posts
    83

    Re: order of applications to process SystemwideHotKey?

    Hannes,

    thanks for your help, but that doesn't do the trick! Here's why:

    My app is supposed to run in the BACKGROUND. I cannot bring it to the foreground.

    I see two ways to solve my problem, but I don't know how to realize that:

    A) I must influence which application is shown the event FIRST. Now if app1 catches <F9-pressed> it reacts to it and THEN puts itself on the bottom of the list of apps that get shown the event the next time it happens. Like that, one after the other of my apps get the chance to see <F9-pressed> the next time.

    B) I let app1 react to <F9-pressed> and then RAISE the event again by app1 and let the other apps react to it. But there are two problems here:
    1) How do I prevent app1 from reacting to it again?
    2) What happens if there are NO other apps to handle the event? Will it remain raised? If so, how can I get app1 to react to it the next time I actually press F9 again?

    I guess that A) would be the best solution, because the events gets handled for sure and there should be no problems the next time the key is pressed.

    So, the main question is: which app catches the event FIRST and WHY? => How can I influence that?

    Any ideas?

  6. #6
    Join Date
    Feb 2000
    Location
    OH - USA
    Posts
    1,892

    Arrow Re: order of applications to process SystemwideHotKey?

    Ok, so it looks like you are using a 3rd party component. We'll just assume that the component is using RegisterHotKey() to get the job done.

    I'm pretty sure that you can only specifically register a hotkey to one hwnd at a time. So we’ll also assume that the component simply un-registers the hotkey if it already exists and registers the latest hwnd, which would fit what you’re describing. What you would need to do for multiple hotkey recipients is to specify a NULL hwnd and parse the message queue for WM_HOTKEY messages.
    Good Luck,
    Craig - CRG IT Solutions - Microsoft Gold Partner

    -My posts after 08/2015 = .NET 4.x and Visual Studio 2015
    -My posts after 11/2011 = .NET 4.x and Visual Studio 2012
    -My posts after 02/2010 = .NET 4.0 and Visual Studio 2010
    -My posts after 12/2007 = .NET 3.5 and Visual Studio 2008
    -My posts after 04/2007 = .NET 3.0 and Visual Studio 2005
    -My posts before 04/2007 = .NET 1.1/2.0

    *I do not follow all threads, so if you have a secondary question, message me.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured