How do you change a string with hexadecimal contents to an int?

Hi, all:

There is a dict:

a = {'F1', 0X79}
a['F1'] = '0X79'

How can i get the value which is int style? but not a str. the result is used for the third parameter ‘virtualKeyCode’ of the wx.Window.RegisterHotKey.
RegisterHotKey ( self , hotkeyId , modifiers , virtualKeyCode )

More context would be helpful. I wonder if you want:

a = {‘F1’: wx.WXK_F1}

  This uses the correct syntax for assigning an element to a

dictionary and uses the convenient wx key constants.

  And be careful.  Function keys can have externally-assigned

meaning that you should not over-ride, and that meaning is
different on different platforms.

David

Thank you, but the parameter is ask for a virtuadlKeyCode that is a hexadecimal integer parameter, but not a wx key.

Take a look at the RegisterHotKey article from the wxPyWiki.

The virtual keycodes you’re looking for are constants defined by Windows; Python by itself doesn’t know anything about Windows specifics, so you need to import the win32con library. It looks like the specific code you want is win32con.VK_F1.

You COULD look up the int value and pass it to RegisterHotKey, but you shouldn’t. “Magic numbers” make your code hard to read and maintain; human-readable constants are your friend.

  • Thank you very much. You solved my problem again. I found all the virtual keys for Windows.

Maybe useful for others, it is here:

VK_CODE = {30: win32con.VK_ACCEPT, 107: win32con.VK_ADD, 93: win32con.VK_APPS, 246: win32con.VK_ATTN, 8: win32con.VK_BACK, 166: win32con.VK_BROWSER_BACK, 167: win32con.VK_BROWSER_FORWARD, 3: win32con.VK_CANCEL, 20: win32con.VK_CAPITAL, 12: win32con.VK_CLEAR, 17: win32con.VK_CONTROL, 28: win32con.VK_CONVERT, 247: win32con.VK_CRSEL, 110: win32con.VK_DECIMAL, 46: win32con.VK_DELETE, 111: win32con.VK_DIVIDE, 40: win32con.VK_DOWN, 35: win32con.VK_END, 249: win32con.VK_EREOF, 27: win32con.VK_ESCAPE, 43: win32con.VK_EXECUTE, 248: win32con.VK_EXSEL, 112: win32con.VK_F1, 121: win32con.VK_F10, 122: win32con.VK_F11, 123: win32con.VK_F12, 124: win32con.VK_F13, 125: win32con.VK_F14, 126: win32con.VK_F15, 127: win32con.VK_F16, 128: win32con.VK_F17, 129: win32con.VK_F18, 130: win32con.VK_F19, 113: win32con.VK_F2, 131: win32con.VK_F20, 132: win32con.VK_F21, 133: win32con.VK_F22, 134: win32con.VK_F23, 135: win32con.VK_F24, 114: win32con.VK_F3, 115: win32con.VK_F4, 116: win32con.VK_F5, 117: win32con.VK_F6, 118: win32con.VK_F7, 119: win32con.VK_F8, 120: win32con.VK_F9, 24: win32con.VK_FINAL, 21: win32con.VK_KANA, 25: win32con.VK_KANJI, 47: win32con.VK_HELP, 36: win32con.VK_HOME, 45: win32con.VK_INSERT, 23: win32con.VK_JUNJA, 1: win32con.VK_LBUTTON, 162: win32con.VK_LCONTROL, 37: win32con.VK_LEFT, 164: win32con.VK_LMENU, 160: win32con.VK_LSHIFT, 91: win32con.VK_LWIN, 4: win32con.VK_MBUTTON, 176: win32con.VK_MEDIA_NEXT_TRACK, 179: win32con.VK_MEDIA_PLAY_PAUSE, 177: win32con.VK_MEDIA_PREV_TRACK, 18: win32con.VK_MENU, 31: win32con.VK_MODECHANGE, 106: win32con.VK_MULTIPLY, 34: win32con.VK_NEXT, 252: win32con.VK_NONAME, 29: win32con.VK_NONCONVERT, 144: win32con.VK_NUMLOCK, 96: win32con.VK_NUMPAD0, 97: win32con.VK_NUMPAD1, 98: win32con.VK_NUMPAD2, 99: win32con.VK_NUMPAD3, 100: win32con.VK_NUMPAD4, 101: win32con.VK_NUMPAD5, 102: win32con.VK_NUMPAD6, 103: win32con.VK_NUMPAD7, 104: win32con.VK_NUMPAD8, 105: win32con.VK_NUMPAD9, 254: win32con.VK_OEM_CLEAR, 253: win32con.VK_PA1, 19: win32con.VK_PAUSE, 250: win32con.VK_PLAY, 42: win32con.VK_PRINT, 33: win32con.VK_PRIOR, 229: win32con.VK_PROCESSKEY, 2: win32con.VK_RBUTTON, 163: win32con.VK_RCONTROL, 13: win32con.VK_RETURN, 39: win32con.VK_RIGHT, 165: win32con.VK_RMENU, 161: win32con.VK_RSHIFT, 92: win32con.VK_RWIN, 145: win32con.VK_SCROLL, 41: win32con.VK_SELECT, 108: win32con.VK_SEPARATOR, 16: win32con.VK_SHIFT, 44: win32con.VK_SNAPSHOT, 32: win32con.VK_SPACE, 109: win32con.VK_SUBTRACT, 9: win32con.VK_TAB, 38: win32con.VK_UP, 174: win32con.VK_VOLUME_DOWN, 173: win32con.VK_VOLUME_MUTE, 175: win32con.VK_VOLUME_UP, 5: win32con.VK_XBUTTON1, 6: win32con.VK_XBUTTON2, 251: win32con.VK_ZOOM}

One example: type(win32con.VK_XBUTTON1), it`s a int class.

Excellent! But once again, the only information you should use from that dict is the names of the aliases, NOT the actual integer values.

In other words, do this:

self.myHotKeyId = 100 
self.RegisterHotKey(
    self.myHotKeyId, 
    win32con.MOD_ALT, 
    win32con.VK_F1)

NOT this:

self.RegisterHotKey(100, 1, 112)