Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > using message loop for hotkey capturing

Reply
Thread Tools

using message loop for hotkey capturing

 
 
Alex Hall
Guest
Posts: n/a
 
      03-23-2010
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.velocityreviews.com/forums/(E-Mail Removed); http://www.facebook.com/mehgcap
 
Reply With Quote
 
 
 
 
bagratte
Guest
Posts: n/a
 
      10-16-2012
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).
 
Reply With Quote
 
 
 
 
bagratte
Guest
Posts: n/a
 
      10-16-2012
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).
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Triple nested loop python (While loop insde of for loop inside ofwhile loop) Isaac Won Python 9 03-04-2013 10:08 AM
Call Manager 3.3(2) and HotKey James Cisco 1 02-22-2005 05:44 AM
Hotkey save functionality in DataGrid =?Utf-8?B?R21hbjk5Nw==?= ASP .Net 0 05-24-2004 11:16 PM
Hotkey (or similar) to kill animations Hiram R. Shadrasky Firefox 3 09-26-2003 03:05 PM
hotkey for e-mail address tawjlee Computer Support 2 09-21-2003 08:46 PM



Advertisments