using message loop for hotkey capturing

Discussion in 'Python' started by Alex Hall, Mar 23, 2010.

  1. Alex Hall

    Alex Hall Guest

    Hi all, but mainly Tim Golden:
    Tim, I am using your wonderful message loop for keyboard input, the
    one on your site that you pointed me to a few months ago. It has been
    working perfectly as long as I had only one dictionary of keys mapping
    to one dictionary of functions, but now I want two of each. My program
    has different modes, which may have varying keystrokes, and I also
    have some global keystrokes which are the same across all modes, like
    exiting or switching modes. I cannot figure out how to make the
    message loop look in two dictionaries at onc. I tried using an if,
    saying that if action_to_take was not set in the mode-specific
    dictionary then look at the global dictionary, but it is like it is
    never looking in the global dictionary at all. I get no syntax errors
    or problems when running the program, so it has to be something in my
    logic. Go to
    http://www.gateway2somewhere.com/sw/main.pyw
    to see what I mean; the problem code is near the very bottom of the
    file. Thanks for any suggestions. Oh, please note that I indent one
    space per indentation level.

    --
    Have a great day,
    Alex (msg sent from GMail website)
    ; http://www.facebook.com/mehgcap
     
    Alex Hall, Mar 23, 2010
    #1
    1. Advertising

  2. Alex Hall

    bagratte Guest

    hi all,

    i am a complete newbie in windows programming and have come across this problem. i wanted a windows systray application which would seat in the notification are, would have a tiny popup menu and would also respond to a globalhotkey. i've assembled something out of the demos in pywin32 which actually works except one thing: i don't like it. i am registering the hotkey within the window class constructor. something like this:

    imports...
    ....

    class MainWindow():
    def __init__(self):
    ...
    user32.RegisterHotKey(None, 1, win32con.MOD_CONTROL, ord('A'))

    message_map = {win32con.WM_DESTROY: self.OnDestroy,
    win32con.WM_COMMAND: self.OnCommand,
    win32con.WM_USER+20: self.OnTaskbarNotify,
    win32con.WM_HOTKEY: self.OnHotKey}
    ...

    def OnCommand(self, hwnd, msg, wparam, lparam):
    print "OnCommand"

    def OnHotKey(self):
    print "OnHotkey"

    def OnDestroy(self, hwnd, msg, wparam, lparam):
    user32.UnregisterHotKey(None, 1)
    ...

    ...

    def myLoop():
    msg = wintypes.MSG()
    while user32.GetMessageA(byref(msg), None, 0, 0) != 0:
    if msg.message == win32con.WM_HOTKEY:
    w.OnHotKey()
    user32.TranslateMessage(byref(msg))
    user32.DispatchMessageA(byref(msg))

    w = MainWindow()
    #PumpMessages()
    myLoop()



    now, if i use myLoop(), which is ripped from tim golden's "home-grown-loop", everything works. however, if i use PumpMessages(), the program won't respond to WM_HOTKEY, and it won't respond to WM_COMMAND (it will respond to WM_USER+20).
    i was wondering if what i've done is not a ridiculously wrong way to do it.in other words, is there any way to make the window respond to WM_HOTKEY thus working with PumpMessages()?

    i thank you all for your patience (this is my first ever windows programming experience).
     
    bagratte, Oct 16, 2012
    #2
    1. Advertising

  3. Alex Hall

    bagratte Guest

    hi all,

    i am a complete newbie in windows programming and have come across this problem. i wanted a windows systray application which would seat in the notification are, would have a tiny popup menu and would also respond to a globalhotkey. i've assembled something out of the demos in pywin32 which actually works except one thing: i don't like it. i am registering the hotkey within the window class constructor. something like this:

    imports...
    ....

    class MainWindow():
    def __init__(self):
    ...
    user32.RegisterHotKey(None, 1, win32con.MOD_CONTROL, ord('A'))

    message_map = {win32con.WM_DESTROY: self.OnDestroy,
    win32con.WM_COMMAND: self.OnCommand,
    win32con.WM_USER+20: self.OnTaskbarNotify,
    win32con.WM_HOTKEY: self.OnHotKey}
    ...

    def OnCommand(self, hwnd, msg, wparam, lparam):
    print "OnCommand"

    def OnHotKey(self):
    print "OnHotkey"

    def OnDestroy(self, hwnd, msg, wparam, lparam):
    user32.UnregisterHotKey(None, 1)
    ...

    ...

    def myLoop():
    msg = wintypes.MSG()
    while user32.GetMessageA(byref(msg), None, 0, 0) != 0:
    if msg.message == win32con.WM_HOTKEY:
    w.OnHotKey()
    user32.TranslateMessage(byref(msg))
    user32.DispatchMessageA(byref(msg))

    w = MainWindow()
    #PumpMessages()
    myLoop()



    now, if i use myLoop(), which is ripped from tim golden's "home-grown-loop", everything works. however, if i use PumpMessages(), the program won't respond to WM_HOTKEY, and it won't respond to WM_COMMAND (it will respond to WM_USER+20).
    i was wondering if what i've done is not a ridiculously wrong way to do it.in other words, is there any way to make the window respond to WM_HOTKEY thus working with PumpMessages()?

    i thank you all for your patience (this is my first ever windows programming experience).
     
    bagratte, Oct 16, 2012
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?R21hbjk5Nw==?=

    Hotkey save functionality in DataGrid

    =?Utf-8?B?R21hbjk5Nw==?=, May 25, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    375
    =?Utf-8?B?R21hbjk5Nw==?=
    May 25, 2004
  2. Replies:
    1
    Views:
    640
  3. Rsrany
    Replies:
    3
    Views:
    381
    Rsrany
    Nov 23, 2005
  4. Luc The Perverse

    Hotkey Manager

    Luc The Perverse, Oct 12, 2006, in forum: Java
    Replies:
    5
    Views:
    455
    Luc The Perverse
    Oct 14, 2006
  5. Isaac Won
    Replies:
    9
    Views:
    388
    Ulrich Eckhardt
    Mar 4, 2013
Loading...

Share This Page