#=============================================================================
# ** Module Keys
#=============================================================================
module Keys
#---------------------------------------------------------------------------
# * Mouse Buttons
#---------------------------------------------------------------------------
MOUSE_LEFT = 1 # Mouse primary button (Normaly the left button)
MOUSE_RIGHT = 2 # Mouse secondary button (Normaly the right button)
MOUSE_MIDDLE = 4 # Mouse middle button
MOUSE_4TH = 5 # Mouse fourth button
MOUSE_5TH = 6 # Mouse fifth button
#---------------------------------------------------------------------------
# * Miscellaneous Keys
#---------------------------------------------------------------------------
CANCEL = 3 # Cancel key
BACKSPACE = 8 # Backspace key
TAB = 9 # Tab key
CLEAR = 12 # Clear key
RETURN = 13 # Enter key
SHIFT = 16 # Shift key
CTRL = 17 # Control key
ALT = 18 # Alt key
PAUSE = 19 # Pause key
ESCAPE = 27 # Escape key
SPACE = 32 # Space bar key
PGUP = 33 # Page Up key
PGDN = 34 # Page Down key
ENDS = 35 # End key
HOME = 36 # Home key
LEFT = 37 # Left Arrow key
UP = 38 # Up Arrow key
RIGHT = 39 # Right Arrow key
DOWN = 40 # Down Arrow key
SNAPSHOT = 44 # Print Screen key
SELECT = 41 # Select key
PRINT = 42 # Print key
EXECUTE = 43 # Execute key
INSERT = 45 # Insert key
DELETE = 46 # Delete key
HELP = 47 # Help key
LEFT_SHIFT = 160 # Left Shift key
RIGHT_SHIFT = 161 # Right Shift key
LEFT_CONTROL = 162 # Left Control key
RIGHT_CONTROL = 163 # Right Control key
LEFT_ALT = 164 # Left Alt key
RIGHT_ALT = 165 # Right Alt key
#---------------------------------------------------------------------------
# * Number Keys
#---------------------------------------------------------------------------
N0 = 48 # 0 key
N1 = 49 # 1 key
N2 = 50 # 2 key
N3 = 51 # 3 key
N4 = 52 # 4 key
N5 = 53 # 5 key
N6 = 54 # 6 key
N7 = 55 # 7 key
N8 = 56 # 8 key
N9 = 57 # 9 key
#---------------------------------------------------------------------------
# * Letters Keys
#---------------------------------------------------------------------------
A = 65 # A key
B = 66 # B key
C = 67 # C key
D = 68 # D key
E = 69 # E key
F = 70 # F key
G = 71 # G key
H = 72 # H key
I = 73 # I key
J = 74 # J key
K = 75 # K key
L = 76 # L key
M = 77 # M key
N = 78 # N key
O = 79 # O key
P = 80 # P key
Q = 81 # Q key
R = 82 # R key
S = 83 # S key
T = 84 # T key
U = 85 # U key
V = 86 # V key
W = 87 # W key
X = 88 # X key
Y = 89 # Y key
Z = 90 # Z key
#---------------------------------------------------------------------------
# * Windows Keys
#---------------------------------------------------------------------------
LWIN = 91 # Left Windows key (Microsoft Natural keyboard)
RWIN = 92 # Right Windows key (Natural keyboard)
APPS = 93 # Applications key (Natural keyboard)
SLEEP = 95 # Computer Sleep key
BROWSER_BAK = 166 # Browser Back key
BROWSER_FORWARD = 167 # Browser Forward key
BROWSER_REFRESH = 168 # Browser Refresh key
BROWSER_STOP = 169 # Browser Stop key
BROWSER_SEARCH = 170 # Browser Search key
BROWSER_FAVORITES = 171 # Browser Favorites key
BROWSER_HOME = 172 # Browser Start and Home key
VOLUME_MUTE = 173 # Volume Mute key
VOLUME_DOWN = 174 # Volume Down key
VOLUME_UP = 175 # Volume Up key
MEDIA_NEXT_TRACK = 176 # Next Track key
MEDIA_PREV_TRACK = 177 # Previous Track key
MEDIA_STOP = 178 # Stop Media key
MEDIA_PLAY_PAUSE = 179 # Play/Pause Media key
LAUNCH_MAIL = 180 # Start Mail key
LAUNCH_MEDIA_SELECT = 181 # Select Media key
LAUNCH_APP1 = 182 # Start Application 1 key
LAUNCH_APP2 = 183 # Start Application 2 key
PROCESS = 229 # Proccess key
ATTN = 246 # Attn key
CRSEL = 247 # CrSel key
EXSEL = 248 # ExSel key
EREOF = 249 # Erase EOF key
PLAY = 250 # Play key
ZOOM = 251 # Zoom key
PA1 = 253 # PA1 key
#---------------------------------------------------------------------------
# * Pad Keys
#---------------------------------------------------------------------------
NUMPAD0 = 96 # 0 key
NUMPAD1 = 97 # 1 key
NUMPAD2 = 98 # 2 key
NUMPAD3 = 99 # 3 key
NUMPAD4 = 100 # 4 key
NUMPAD5 = 101 # 5 key
NUMPAD6 = 102 # 6 key
NUMPAD7 = 103 # 7 key
NUMPAD8 = 104 # 8 key
NUMPAD9 = 105 # 9 key
MULTIPLY = 106 # Multiply key (*)
ADD = 107 # Add key (+)
SEPARATOR = 108 # Separator key
SUBTRACT = 109 # Subtract key (-)
DECIMAL = 110 # Decimal key (.)
DIVIDE = 111 # Divide key (/)
#---------------------------------------------------------------------------
# * F Keys
#---------------------------------------------------------------------------
F1 = 112 # F1 key
F2 = 113 # F2 key
F3 = 114 # F3 key
F4 = 115 # F4 key
F5 = 116 # F5 key
F6 = 117 # F6 key
F7 = 118 # F7 key
F8 = 119 # F8 key
F9 = 120 # F9 key
F10 = 121 # F10 key
F11 = 122 # F11 key
F12 = 123 # F12 key
F13 = 124 # F13 key
F14 = 125 # F14 key
F15 = 126 # F15 key
F16 = 127 # F16 key
F17 = 128 # F17 key
F18 = 129 # F18 key
F19 = 130 # F19 key
F20 = 131 # F20 key
F21 = 132 # F21 key
F22 = 133 # F22 key
F23 = 134 # F23 key
F24 = 135 # F24 key
#---------------------------------------------------------------------------
# * Mode Keys
#---------------------------------------------------------------------------
CAPS_LOCK = 20 # Caps lock key
NUM_LOCK = 144 # Num lock key
SCROLL_LOCK = 145 # Scroll lock key
KANA = 21 # Kana key
JUNJA = 23 # Junja key
FINAL = 24 # Final key
KANJI = 25 # Kanji key
CONVERT = 28 # Convert key
NONCONVERT = 29 # Non convert key
ACCEPT = 30 # Accept key
MODECHANGE = 31 # Mode change request key
#---------------------------------------------------------------------------
# * OEM Keys
# - Keys used for miscellaneous characters; they can vary by keyboard.
#---------------------------------------------------------------------------
OEM_1 = 186 # In USA 101/102 keyboards (; :)
OEM_2 = 187 # In USA 101/102 keyboards (= +)
OEM_3 = 188 # In USA 101/102 keyboards (, <)
OEM_4 = 189 # In USA 101/102 keyboards (- _)
OEM_5 = 190 # In USA 101/102 keyboards (. >)
OEM_6 = 191 # In USA 101/102 keyboards (/ ?)
OEM_7 = 192 # In USA 101/102 keyboards (` ~)
OEM_8 = 219 # In USA 101/102 keyboards ([ {)
OEM_9 = 220 # In USA 101/102 keyboards (\ |)
OEM_10 = 221 # In USA 101/102 keyboards (] })
OEM_11 = 222 # In USA 101/102 keyboards (' ")
OEM_13 = 223 # OEM key
OEM_14 = 226 # OEM key
OEM_15 = 146 # OEM key
OEM_16 = 147 # OEM key
OEM_17 = 148 # OEM key
OEM_18 = 149 # OEM key
OEM_19 = 150 # OEM key
OEM_20 = 225 # OEM key
OEM_21 = 227 # OEM key
OEM_22 = 228 # OEM key
OEM_23 = 230 # OEM key
OEM_24 = 232 # OEM key
OEM_25 = 240 # OEM key
OEM_26 = 241 # OEM key
OEM_27 = 242 # OEM key
OEM_28 = 243 # OEM key
OEM_29 = 244 # OEM key
OEM_30 = 245 # OEM key
OEM_CLEAR = 254 # OEM Clear key
#---------------------------------------------------------------------------
# * Keys Names
#---------------------------------------------------------------------------
KEYS_NAMES = {1=>'Mouse Primary',2=>'Mouse Secondary',3=>'Cancel',
4=>'Mouse Middle',5=>'Mouse 4th',6=>'Mouse 5th',8=>'Backspace',9=>'Tab',
12=>'Clear',13=>'Enter',16=>'Shift',17=>'Control',18=>'Alt',19=>'Pause',
20=>'Capitals Lock',21=>'Kana',23=>'Junja',24=>'Final',25=>'Kanji',
27=>'Escape',28=>'Convert',29=>'Non Convert',30=>'Accept',31=>'Mode Change',
32=>'Space',33=>'Page Up',34=>'Page Down',35=>'End',36=>'Home',37=>'Left',
38=>'Up',39=>'Right',40=>'Down',41=>'Select',42=>'Print',43=>'Execute',
44=>'Snapshot',45=>'Insert',46=>'Delete',47=>'Help',48=>'0',49=>'1',50=>'2',
51=>'3',52=>'4',53=>'5',54=>'6',55=>'7',56=>'8',57=>'9',65=>'A',66=>'B',
67=>'C',68=>'D',69=>'E',70=>'F',71=>'G',72=>'H',73=>'I',74=>'J',75=>'K',
76=>'L',77=>'M',78=>'N',79=>'O',80=>'P',81=>'Q',82=>'R',83=>'S',84=>'T',
85=>'U',86=>'V',87=>'W',88=>'X',89=>'Y',90=>'Z',91=>'Left Windows',
92=>'Right Windows',93=>'Application',95=>'Sleep',96=>'PAD 0',97=>'PAD 1',
98=>'PAD 2',99=>'PAD 3',100=>'PAD 4',101=>'PAD 5',102=>'PAD 6',103=>'PAD 7',
104=>'PAD 8',105=>'PAD 9',106=>'*',107=>'+',108=>'Separator',109=>'-',110=>'.',
111=>'/',112=>'F1',113=>'F2',114=>'F3',115=>'F4',116=>'F5',117=>'F6',118=>'F7',
119=>'F8',120=>'F9',121=>'F10',122=>'F11',123=>'F12',124=>'F13',125=>'F14',
126=>'F15',127=>'F16',128=>'F17',129=>'F18',130=>'F19',131=>'F20',132=>'F21',
133=>'F22',134=>'F23',135=>'F24',144=>'Number Lock',145=>'Scroll Lock',
146=>'OEM 15',147=>'OEM 16',148=>'OEM 17',149=>'OEM 18',150=>'OEM 19',
160=>'Left Shift',161=>'Right Shift',162=>' Left Control',163=>'Right Control',
164=>' Left Alt',165=>'Right Alt',166=>'Browser Back',167=>'Browser Forward',
168=>'Browser Refresh',169=>'Browser Stop',170=>'Browser Search',
171=>'Browser Favorites',172=>'Browser Home',173=>'Volume Mute',
174=>'Volume Down',175=>'Volume Up',176=>'Media Next Track',
177=>'Media Previous Track',178=>'Media Stop',179=>'Media Play Pause',
180=>'Launch Mail',181=>'Launch Media Select',182=>'Launch Application',
183=>'Launch Application',186=>'OEM 1',187=>'OEM 2',188=>'OEM 3',189=>'OEM 4',
190=>'OEM 5',191=>'OEM 6',192=>'OEM 7',219=>'OEM 8',220=>'OEM 9',221=>'OEM 10',
222=>'OEM 11',223=>'OEM 13',225=>'OEM 20',226=>'OEM 14',227=>'OEM 21',
228=>'OEM 22',229=>'Proccess',230=>'OEM 23',232=>'OEM 24',240=>'OEM 25',
241=>'OEM 26',242=>'OEM 27',243=>'OEM 28',244=>'OEM 29',245=>'OEM 30',
246=>'ATTN',247=>'CRSEL',248=>'EXSEL',249=>'EREOF',250=>'Play',251=>'Zoom',
253=>'PA1',254=>'OEM Clear'}
#---------------------------------------------------------------------------
# * Virtual Key to Key Name
#---------------------------------------------------------------------------
def Keys.name?(vk)
KEYS_NAMES[vk].nil? ? '???' : KEYS_NAMES[vk]
end
#---------------------------------------------------------------------------
# * Virtual Key to Virtual Key Variable Name
#---------------------------------------------------------------------------
def Keys.var_name?(vk)
Keys.constants.size.times do |index|
if eval("Keys::#{Keys.constants[index]}") == vk
return Keys.constants[index]
end
end
'???'
end
#---------------------------------------------------------------------------
# * Key Name to Virtual Key
#---------------------------------------------------------------------------
def Keys.vk?(name)
KEYS_NAMES.invert[name].nil? ? 0 : KEYS_NAMES.invert[name]
end
#---------------------------------------------------------------------------
# * Virtual Key Variable Name to Virtual Key
#---------------------------------------------------------------------------
def Keys.var_vk?(name)
if Keys.constants.include?(name)
eval("Keys::#{Keys.constants[Keys.constants.index(name)]}")
else
0
end
end
end