From 5d0d9216de1dee10a4fa18e5337a408baa9dabc6 Mon Sep 17 00:00:00 2001 From: James Turk Date: Sun, 15 May 2011 20:19:34 -0400 Subject: [PATCH] keycode constants --- photon/keyboard.py | 506 +++++++++++++++++++++++++++++++++- photon/tests/test_keyboard.py | 11 +- 2 files changed, 510 insertions(+), 7 deletions(-) diff --git a/photon/keyboard.py b/photon/keyboard.py index 538f055..46eafb2 100644 --- a/photon/keyboard.py +++ b/photon/keyboard.py @@ -1,8 +1,8 @@ import ctypes from .internal import _SDL +from .enum import CEnum -# SDL_GetKeyboardFocus -# have this return a Window() object +# TODO: GetKeyboardFocus - have this return a Window() object _SDL.SDL_GetKeyboardState.restype = ctypes.POINTER(ctypes.c_uint8) _keyboard_state = None @@ -41,3 +41,505 @@ def stop_text_input(): def set_text_input_rect(rect): _SDL.SDL_SetTextInputRect(rect) + + +class Keymod(CEnum): + NONE = 0x0000 + LSHIFT = 0x0001 + RSHIFT = 0x0002 + SHIFT = 0x0001 | 0x0002 + LCTRL = 0x0040 + RCTRL = 0x0080 + CTRL = 0x0040 | 0x0080 + LALT = 0x0100 + RALT = 0x0200 + ALT = 0x0100 | 0x0200 + LGUI = 0x0400 + RGUI = 0x0800 + GUI = 0x0400 | 0x0800 + NUM = 0x1000 + CAPS = 0x2000 + MODE = 0x4000 + RESERVED = 0x8000 + +class Scancode(CEnum): + UNKNOWN = 0x000 + A = 0x004 + B = 0x005 + C = 0x006 + D = 0x007 + E = 0x008 + F = 0x009 + G = 0x00A + H = 0x00B + I = 0x00C + J = 0x00D + K = 0x00E + L = 0x00F + M = 0x010 + N = 0x011 + O = 0x012 + P = 0x013 + Q = 0x014 + R = 0x015 + S = 0x016 + T = 0x017 + U = 0x018 + V = 0x019 + W = 0x01A + X = 0x01B + Y = 0x01C + Z = 0x01D + ONE = 0x01E + TWO = 0x01F + THREE = 0x020 + FOUR = 0x021 + FIVE = 0x022 + SIX = 0x023 + SEVEN = 0x024 + EIGHT = 0x025 + NINE = 0x026 + ZERO = 0x027 + RETURN = 0x028 + ESCAPE = 0x029 + BACKSPACE = 0x02A + TAB = 0x02B + SPACE = 0x02C + MINUS = 0x02D + EQUALS = 0x02E + LEFTBRACKET = 0x02F + RIGHTBRACKET = 0x030 + BACKSLASH = 0x031 + NONUSHASH = 0x032 + SEMICOLON = 0x033 + APOSTROPHE = 0x034 + GRAVE = 0x035 + COMMA = 0x036 + PERIOD = 0x037 + SLASH = 0x038 + CAPSLOCK = 0x039 + F1 = 0x03A + F2 = 0x03B + F3 = 0x03C + F4 = 0x03D + F5 = 0x03E + F6 = 0x03F + F7 = 0x040 + F8 = 0x041 + F9 = 0x042 + F10 = 0x043 + F11 = 0x044 + F12 = 0x045 + PRINTSCREEN = 0x046 + SCROLLLOCK = 0x047 + PAUSE = 0x048 + INSERT = 0x049 + HOME = 0x04A + PAGEUP = 0x04B + DELETE = 0x04C + END = 0x04D + PAGEDOWN = 0x04E + RIGHT = 0x04F + LEFT = 0x050 + DOWN = 0x051 + UP = 0x052 + NUMLOCKCLEAR = 0x053 + KP_DIVIDE = 0x054 + KP_MULTIPLY = 0x055 + KP_MINUS = 0x056 + KP_PLUS = 0x057 + KP_ENTER = 0x058 + KP_1 = 0x059 + KP_2 = 0x05A + KP_3 = 0x05B + KP_4 = 0x05C + KP_5 = 0x05D + KP_6 = 0x05E + KP_7 = 0x05F + KP_8 = 0x060 + KP_9 = 0x061 + KP_0 = 0x062 + KP_PERIOD = 0x063 + NONUSBACKSLASH = 0x064 + APPLICATION = 0x065 + POWER = 0x066 + KP_EQUALS = 0x067 + F13 = 0x068 + F14 = 0x069 + F15 = 0x06A + F16 = 0x06B + F17 = 0x06C + F18 = 0x06D + F19 = 0x06E + F20 = 0x06F + F21 = 0x070 + F22 = 0x071 + F23 = 0x072 + F24 = 0x073 + EXECUTE = 0x074 + HELP = 0x075 + MENU = 0x076 + SELECT = 0x077 + STOP = 0x078 + AGAIN = 0x079 + UNDO = 0x07A + CUT = 0x07B + COPY = 0x07C + PASTE = 0x07D + FIND = 0x07E + MUTE = 0x07F + VOLUMEUP = 0x080 + VOLUMEDOWN = 0x081 + LOCKINGCAPSLOCK = 0x082 + LOCKINGNUMLOCK = 0x083 + LOCKINGSCROLLLOCK = 0x084 + KP_COMMA = 0x085 + KP_EQUALSAS400 = 0x086 + INTERNATIONAL1 = 0x087 + INTERNATIONAL2 = 0x088 + INTERNATIONAL3 = 0x089 + INTERNATIONAL4 = 0x08A + INTERNATIONAL5 = 0x08B + INTERNATIONAL6 = 0x08C + INTERNATIONAL7 = 0x08D + INTERNATIONAL8 = 0x08E + INTERNATIONAL9 = 0x08F + LANG1 = 0x090 + LANG2 = 0x091 + LANG3 = 0x092 + LANG4 = 0x093 + LANG5 = 0x094 + LANG6 = 0x095 + LANG7 = 0x096 + LANG8 = 0x097 + LANG9 = 0x098 + ALTERASE = 0x099 + SYSREQ = 0x09A + CANCEL = 0x09B + CLEAR = 0x09C + PRIOR = 0x09D + RETURN2 = 0x09E + SEPARATOR = 0x09F + OUT = 0x0A0 + OPER = 0x0A1 + CLEARAGAIN = 0x0A2 + CRSEL = 0x0A3 + EXSEL = 0x0A4 + KP_00 = 0x0B0 + KP_000 = 0x0B1 + THOUSANDSSEPARATOR = 0x0B2 + DECIMALSEPARATOR = 0x0B3 + CURRENCYUNIT = 0x0B4 + CURRENCYSUBUNIT = 0x0B5 + KP_LEFTPAREN = 0x0B6 + KP_RIGHTPAREN = 0x0B7 + KP_LEFTBRACE = 0x0B8 + KP_RIGHTBRACE = 0x0B9 + KP_TAB = 0x0BA + KP_BACKSPACE = 0x0BB + KP_A = 0x0BC + KP_B = 0x0BD + KP_C = 0x0BE + KP_D = 0x0BF + KP_E = 0x0C0 + KP_F = 0x0C1 + KP_XOR = 0x0C2 + KP_POWER = 0x0C3 + KP_PERCENT = 0x0C4 + KP_LESS = 0x0C5 + KP_GREATER = 0x0C6 + KP_AMPERSAND = 0x0C7 + KP_DBLAMPERSAND = 0x0C8 + KP_VERTICALBAR = 0x0C9 + KP_DBLVERTICALBAR = 0x0CA + KP_COLON = 0x0CB + KP_HASH = 0x0CC + KP_SPACE = 0x0CD + KP_AT = 0x0CE + KP_EXCLAM = 0x0CF + KP_MEMSTORE = 0x0D0 + KP_MEMRECALL = 0x0D1 + KP_MEMCLEAR = 0x0D2 + KP_MEMADD = 0x0D3 + KP_MEMSUBTRACT = 0x0D4 + KP_MEMMULTIPLY = 0x0D5 + KP_MEMDIVIDE = 0x0D6 + KP_PLUSMINUS = 0x0D7 + KP_CLEAR = 0x0D8 + KP_CLEARENTRY = 0x0D9 + KP_BINARY = 0x0DA + KP_OCTAL = 0x0DB + KP_DECIMAL = 0x0DC + KP_HEXADECIMAL = 0x0DD + LCTRL = 0x0E0 + LSHIFT = 0x0E1 + LALT = 0x0E2 + LGUI = 0x0E3 + RCTRL = 0x0E4 + RSHIFT = 0x0E5 + RALT = 0x0E6 + RGUI = 0x0E7 + MODE = 0x101 + AUDIONEXT = 0x102 + AUDIOPREV = 0x103 + AUDIOSTOP = 0x104 + AUDIOPLAY = 0x105 + AUDIOMUTE = 0x106 + MEDIASELECT = 0x107 + WWW = 0x108 + MAIL = 0x109 + CALCULATOR = 0x10A + COMPUTER = 0x10B + AC_SEARCH = 0x10C + AC_HOME = 0x10D + AC_BACK = 0x10E + AC_FORWARD = 0x10F + AC_STOP = 0x110 + AC_REFRESH = 0x111 + AC_BOOKMARKS = 0x112 + BRIGHTNESSDOWN = 0x113 + BRIGHTNESSUP = 0x114 + DISPLAYSWITCH = 0x115 + KBDILLUMTOGGLE = 0x116 + KBDILLUMDOWN = 0x117 + KBDILLUMUP = 0x118 + EJECT = 0x119 + SLEEP = 0x11A + +class Keycode(CEnum): + UNKNOWN = 0x00 + BACKSPACE = 0x08 + TAB = 0x09 + RETURN = 0x0D + ESCAPE = 0x1B + SPACE = 0x20 + EXCLAIM = 0x21 + QUOTEDBL = 0x22 + HASH = 0x23 + DOLLAR = 0x24 + PERCENT = 0x25 + AMPERSAND = 0x26 + QUOTE = 0x27 + LEFTPAREN = 0x28 + RIGHTPAREN = 0x29 + ASTERISK = 0x2A + PLUS = 0x2B + COMMA = 0x2C + MINUS = 0x2D + PERIOD = 0x2E + SLASH = 0x2F + ZERO = 0x30 + ONE = 0x31 + TWO = 0x32 + THREE = 0x33 + FOUR = 0x34 + FIVE = 0x35 + SIX = 0x36 + SEVEN = 0x37 + EIGHT = 0x38 + NINE = 0x39 + COLON = 0x3A + SEMICOLON = 0x3B + LESS = 0x3C + EQUALS = 0x3D + GREATER = 0x3E + QUESTION = 0x3F + AT = 0x40 + LEFTBRACKET = 0x5B + BACKSLASH = 0x5C + RIGHTBRACKET = 0x5D + CARET = 0x5E + UNDERSCORE = 0x5F + BACKQUOTE = 0x60 + a = 0x61 + b = 0x62 + c = 0x63 + d = 0x64 + e = 0x65 + f = 0x66 + g = 0x67 + h = 0x68 + i = 0x69 + j = 0x6A + k = 0x6B + l = 0x6C + m = 0x6D + n = 0x6E + o = 0x6F + p = 0x70 + q = 0x71 + r = 0x72 + s = 0x73 + t = 0x74 + u = 0x75 + v = 0x76 + w = 0x77 + x = 0x78 + y = 0x79 + z = 0x7A + DELETE = 0xB1 + CAPSLOCK = 0x40000039 + F1 = 0x4000003A + F2 = 0x4000003B + F3 = 0x4000003C + F4 = 0x4000003D + F5 = 0x4000003E + F6 = 0x4000003F + F7 = 0x40000040 + F8 = 0x40000041 + F9 = 0x40000042 + F10 = 0x40000043 + F11 = 0x40000044 + F12 = 0x40000045 + PRINTSCREEN = 0x40000046 + SCROLLLOCK = 0x40000047 + PAUSE = 0x40000048 + INSERT = 0x40000049 + HOME = 0x4000004A + PAGEUP = 0x4000004B + END = 0x4000004D + PAGEDOWN = 0x4000004E + RIGHT = 0x4000004F + LEFT = 0x40000050 + DOWN = 0x40000051 + UP = 0x40000052 + NUMLOCKCLEAR = 0x40000053 + KP_DIVIDE = 0x40000054 + KP_MULTIPLY = 0x40000055 + KP_MINUS = 0x40000056 + KP_PLUS = 0x40000057 + KP_ENTER = 0x40000058 + KP_1 = 0x40000059 + KP_2 = 0x4000005A + KP_3 = 0x4000005B + KP_4 = 0x4000005C + KP_5 = 0x4000005D + KP_6 = 0x4000005E + KP_7 = 0x4000005F + KP_8 = 0x40000060 + KP_9 = 0x40000061 + KP_0 = 0x40000062 + KP_PERIOD = 0x40000063 + APPLICATION = 0x40000065 + POWER = 0x40000066 + KP_EQUALS = 0x40000067 + F13 = 0x40000068 + F14 = 0x40000069 + F15 = 0x4000006A + F16 = 0x4000006B + F17 = 0x4000006C + F18 = 0x4000006D + F19 = 0x4000006E + F20 = 0x4000006F + F21 = 0x40000070 + F22 = 0x40000071 + F23 = 0x40000072 + F24 = 0x40000073 + EXECUTE = 0x40000074 + HELP = 0x40000075 + MENU = 0x40000076 + SELECT = 0x40000077 + STOP = 0x40000078 + AGAIN = 0x40000079 + UNDO = 0x4000007A + CUT = 0x4000007B + COPY = 0x4000007C + PASTE = 0x4000007D + FIND = 0x4000007E + MUTE = 0x4000007F + VOLUMEUP = 0x40000080 + VOLUMEDOWN = 0x40000081 + KP_COMMA = 0x40000085 + KP_EQUALSAS400 = 0x40000086 + ALTERASE = 0x40000099 + SYSREQ = 0x4000009A + CANCEL = 0x4000009B + CLEAR = 0x4000009C + PRIOR = 0x4000009D + RETURN2 = 0x4000009E + SEPARATOR = 0x4000009F + OUT = 0x400000A0 + OPER = 0x400000A1 + CLEARAGAIN = 0x400000A2 + CRSEL = 0x400000A3 + EXSEL = 0x400000A4 + KP_00 = 0x400000B0 + KP_000 = 0x400000B1 + THOUSANDSSEPARATOR = 0x400000B2 + DECIMALSEPARATOR = 0x400000B3 + CURRENCYUNIT = 0x400000B4 + CURRENCYSUBUNIT = 0x400000B5 + KP_LEFTPAREN = 0x400000B6 + KP_RIGHTPAREN = 0x400000B7 + KP_LEFTBRACE = 0x400000B8 + KP_RIGHTBRACE = 0x400000B9 + KP_TAB = 0x400000BA + KP_BACKSPACE = 0x400000BB + KP_A = 0x400000BC + KP_B = 0x400000BD + KP_C = 0x400000BE + KP_D = 0x400000BF + KP_E = 0x400000C0 + KP_F = 0x400000C1 + KP_XOR = 0x400000C2 + KP_POWER = 0x400000C3 + KP_PERCENT = 0x400000C4 + KP_LESS = 0x400000C5 + KP_GREATER = 0x400000C6 + KP_AMPERSAND = 0x400000C7 + KP_DBLAMPERSAND = 0x400000C8 + KP_VERTICALBAR = 0x400000C9 + KP_DBLVERTICALBAR = 0x400000CA + KP_COLON = 0x400000CB + KP_HASH = 0x400000CC + KP_SPACE = 0x400000CD + KP_AT = 0x400000CE + KP_EXCLAM = 0x400000CF + KP_MEMSTORE = 0x400000D0 + KP_MEMRECALL = 0x400000D1 + KP_MEMCLEAR = 0x400000D2 + KP_MEMADD = 0x400000D3 + KP_MEMSUBTRACT = 0x400000D4 + KP_MEMMULTIPLY = 0x400000D5 + KP_MEMDIVIDE = 0x400000D6 + KP_PLUSMINUS = 0x400000D7 + KP_CLEAR = 0x400000D8 + KP_CLEARENTRY = 0x400000D9 + KP_BINARY = 0x400000DA + KP_OCTAL = 0x400000DB + KP_DECIMAL = 0x400000DC + KP_HEXADECIMAL = 0x400000DD + LCTRL = 0x400000E0 + LSHIFT = 0x400000E1 + LALT = 0x400000E2 + LGUI = 0x400000E3 + RCTRL = 0x400000E4 + RSHIFT = 0x400000E5 + RALT = 0x400000E6 + RGUI = 0x400000E7 + MODE = 0x40000101 + AUDIONEXT = 0x40000102 + AUDIOPREV = 0x40000103 + AUDIOSTOP = 0x40000104 + AUDIOPLAY = 0x40000105 + AUDIOMUTE = 0x40000106 + MEDIASELECT = 0x40000107 + WWW = 0x40000108 + MAIL = 0x40000109 + CALCULATOR = 0x4000010A + COMPUTER = 0x4000010B + AC_SEARCH = 0x4000010C + AC_HOME = 0x4000010D + AC_BACK = 0x4000010E + AC_FORWARD = 0x4000010F + AC_STOP = 0x40000110 + AC_REFRESH = 0x40000111 + AC_BOOKMARKS = 0x40000112 + BRIGHTNESSDOWN = 0x40000113 + BRIGHTNESSUP = 0x40000114 + DISPLAYSWITCH = 0x40000115 + KBDILLUMTOGGLE = 0x40000116 + KBDILLUMDOWN = 0x40000117 + KBDILLUMUP = 0x40000118 + EJECT = 0x40000119 + SLEEP = 0x4000011A diff --git a/photon/tests/test_keyboard.py b/photon/tests/test_keyboard.py index d1ce67f..d7cbc6e 100644 --- a/photon/tests/test_keyboard.py +++ b/photon/tests/test_keyboard.py @@ -1,14 +1,15 @@ from .. import init, InitFlags from ..keyboard import (get_mod_state, set_mod_state, get_key_from_scancode, - get_scancode_from_key, get_key_name, get_scancode_name) + get_scancode_from_key, get_key_name, get_scancode_name, + Scancode, Keycode) from nose.tools import with_setup _keys = [ # scancode, keycode, name - (40, 13, 'Return'), - (4, 97, 'A'), - (87, 1073741911, 'Keypad +'), - (225, 1073742049, 'Left Shift') + (Scancode.RETURN, Keycode.RETURN, 'Return'), + (Scancode.A, Keycode.a, 'A'), + (Scancode.KP_PLUS, Keycode.KP_PLUS, 'Keypad +'), + (Scancode.LSHIFT, Keycode.LSHIFT, 'Left Shift') ] def init_everything():