wxpython how to reigster global hotkey

I try pyhk, too much reliance on.

My require hotkeys for keyboard, for example:

hot.addHotkey([‘Ctrl’, ‘Alt’,‘f1’], fun)

hope support window + mac

···


jiang zhixiang

While I am not 100% sure of what you are asking, I believe you may want to check out accelerator tables. Using Mike Driscoll’s blog as a guide wxPython Keyboard Shortcuts (accelerators) I was able to get around an annoying issue with one of my programs not properly using Ctrl+C to copy data to the pc clipboard.

···

On Thursday, June 12, 2014 3:45:20 AM UTC-4, luckrill wrote:

I try pyhk, too much reliance on.

My require hotkeys for keyboard, for example:

hot.addHotkey([‘Ctrl’, ‘Alt’,‘f1’], fun)

hope support window + mac


jiang zhixiang

That certainly sounds like an AccleratorTable would solve the problem. If the OP needs to get lower level, then they’ll want to try binding to EVT_KEY_DOWN or possibly EVT_CHAR. I would definitely start with the AccleratorTable though.

Mike

···

On Thursday, June 12, 2014 3:36:29 PM UTC-5, Mike Stover wrote:

While I am not 100% sure of what you are asking, I believe you may want to check out accelerator tables. Using Mike Driscoll’s blog as a guide wxPython Keyboard Shortcuts (accelerators) I was able to get around an annoying issue with one of my programs not properly using Ctrl+C to copy data to the pc clipboard.

I found RegisterHotKey() can help me.

    self.regHotKey()
    self.Bind(wx.EVT_HOTKEY, self.handleHotKey, id=self.hotKeyId)
   
def regHotKey(self):
    # This function registers the hotkey Alt+F1 with id=100
    self.hotKeyId = 100
    self.RegisterHotKey(
        self.hotKeyId, #a unique ID for this hotkey
        win32con.MOD_CONTROL | win32con.MOD_ALT, #the modifier key
        win32con.VK_F1) #the key to watch for
   
def handleHotKey(self, evt):
    print "do hot key actions"
···

2014-06-13 4:54 GMT+08:00 Mike Driscoll kyosohma@gmail.com:

On Thursday, June 12, 2014 3:36:29 PM UTC-5, Mike Stover wrote:

While I am not 100% sure of what you are asking, I believe you may want to check out accelerator tables. Using Mike Driscoll’s blog as a guide wxPython Keyboard Shortcuts (accelerators) I was able to get around an annoying issue with one of my programs not properly using Ctrl+C to copy data to the pc clipboard.

That certainly sounds like an AccleratorTable would solve the problem. If the OP needs to get lower level, then they’ll want to try binding to EVT_KEY_DOWN or possibly EVT_CHAR. I would definitely start with the AccleratorTable though.

Mike

You received this message because you are subscribed to the Google Groups “wxPython-users” group.

To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-users+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.


jiang zhixiang

While this will work on Windows I do not believe it will work for Mac’s due to the use of win32con to bind the keys. By using the accelerator tables and Mike Driscoll’s suggestion of catching EVT_KEY_DOWN and EVT_CHAR it will be easier to support multiple OS platforms. Of course you could add more to the code of your program that would detect the running OS and switch how it will bind the keys, it may just take more time and coding to get it working.

···

On Friday, June 13, 2014 3:44:34 AM UTC-4, luckrill wrote:

I found RegisterHotKey() can help me.

    self.regHotKey()
    self.Bind(wx.EVT_HOTKEY, self.handleHotKey, id=self.hotKeyId)
   
def regHotKey(self):
    # This function registers the hotkey Alt+F1 with id=100
    self.hotKeyId = 100
    self.RegisterHotKey(
        self.hotKeyId, #a unique ID for this hotkey
        win32con.MOD_CONTROL | win32con.MOD_ALT, #the modifier key
        win32con.VK_F1) #the key to watch for
   
def handleHotKey(self, evt):
    print "do hot key actions"

2014-06-13 4:54 GMT+08:00 Mike Driscoll kyos...@gmail.com:

On Thursday, June 12, 2014 3:36:29 PM UTC-5, Mike Stover wrote:

While I am not 100% sure of what you are asking, I believe you may want to check out accelerator tables. Using Mike Driscoll’s blog as a guide wxPython Keyboard Shortcuts (accelerators) I was able to get around an annoying issue with one of my programs not properly using Ctrl+C to copy data to the pc clipboard.

That certainly sounds like an AccleratorTable would solve the problem. If the OP needs to get lower level, then they’ll want to try binding to EVT_KEY_DOWN or possibly EVT_CHAR. I would definitely start with the AccleratorTable though.

Mike

You received this message because you are subscribed to the Google Groups “wxPython-users” group.

To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-user...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.


jiang zhixiang

You are correct. Anytime you use a module from PyWin32, it will only work
on Windows. This code will NOT work on Mac or Linux.

···

On Fri, Jun 13, 2014 at 7:38 AM, Mike Stover <hakugin.gin@gmail.com> wrote:

While this will work on Windows I do not believe it will work for Mac's
due to the use of *win32con* to bind the keys. By using the accelerator
tables and Mike Driscoll's suggestion of catching EVT_KEY_DOWN and EVT_CHAR
it will be easier to support multiple OS platforms. Of course you could add
more to the code of your program that would detect the running OS and
switch how it will bind the keys, it may just take more time and coding to
get it working.

-----------------
Mike Driscoll

Blog: http://blog.pythonlibrary.org
Book: Python 101