correct definitions for win32 key codes VK_*
This commit is contained in:
		
							parent
							
								
									509f82d04d
								
							
						
					
					
						commit
						467eeaf217
					
				
							
								
								
									
										103
									
								
								src/keycodes.h
									
									
									
									
									
								
							
							
						
						
									
										103
									
								
								src/keycodes.h
									
									
									
									
									
								
							@ -24,6 +24,8 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#if defined(USE_SDL) || defined(USE_SDL2)
 | 
					#if defined(USE_SDL) || defined(USE_SDL2)
 | 
				
			||||||
#include <SDL.h>
 | 
					#include <SDL.h>
 | 
				
			||||||
 | 
					#elif defined(WIN32)
 | 
				
			||||||
 | 
					#include <windows.h>
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#if defined(USE_SDL)
 | 
					#if defined(USE_SDL)
 | 
				
			||||||
@ -148,6 +150,107 @@
 | 
				
			|||||||
#define KEY_F11          K2K(SDLK_F11)
 | 
					#define KEY_F11          K2K(SDLK_F11)
 | 
				
			||||||
#define KEY_F12          K2K(SDLK_F12)
 | 
					#define KEY_F12          K2K(SDLK_F12)
 | 
				
			||||||
// end of KEY definitions for SDL and SDL2
 | 
					// end of KEY definitions for SDL and SDL2
 | 
				
			||||||
 | 
					#elif defined(WIN32)
 | 
				
			||||||
 | 
					// KEY definitions for win32
 | 
				
			||||||
 | 
					#define KEY_UNKNOWN      0
 | 
				
			||||||
 | 
					#define KEY_ESCAPE       VK_ESCAPE
 | 
				
			||||||
 | 
					#define KEY_RETURN       VK_RETURN
 | 
				
			||||||
 | 
					#define KEY_BACKSPACE    VK_BACK
 | 
				
			||||||
 | 
					#define KEY_TAB          VK_TAB
 | 
				
			||||||
 | 
					#define KEY_UP           VK_UP
 | 
				
			||||||
 | 
					#define KEY_DOWN         VK_DOWN
 | 
				
			||||||
 | 
					#define KEY_LEFT         VK_LEFT
 | 
				
			||||||
 | 
					#define KEY_RIGHT        VK_RIGHT
 | 
				
			||||||
 | 
					#define KEY_LEFTBRACKET  VK_OEM_4
 | 
				
			||||||
 | 
					#define KEY_RIGHTBRACKET VK_OEM_6
 | 
				
			||||||
 | 
					#define KEY_INSERT       VK_INSERT
 | 
				
			||||||
 | 
					#define KEY_DELETE       VK_DELETE
 | 
				
			||||||
 | 
					#define KEY_COMMA        VK_OEM_COMMA
 | 
				
			||||||
 | 
					#define KEY_BACKQUOTE    VK_OEM_3
 | 
				
			||||||
 | 
					#define KEY_PAGEUP       VK_PRIOR
 | 
				
			||||||
 | 
					#define KEY_PAGEDOWN     VK_NEXT
 | 
				
			||||||
 | 
					#define KEY_HOME         VK_HOME
 | 
				
			||||||
 | 
					#define KEY_END          VK_END
 | 
				
			||||||
 | 
					#define KEY_KP_PLUS      VK_ADD
 | 
				
			||||||
 | 
					#define KEY_KP_MINUS     VK_SUBTRACT
 | 
				
			||||||
 | 
					#define KEY_KP_MULTIPLY  VK_MULTIPLY
 | 
				
			||||||
 | 
					#define KEY_KP_ENTER     VK_RETURN
 | 
				
			||||||
 | 
					#define KEY_KP_DIVIDE    VK_DIVIDE
 | 
				
			||||||
 | 
					#define KEY_KP_PERIOD    VK_DECIMAL
 | 
				
			||||||
 | 
					#define KEY_KP_EQUALS    0
 | 
				
			||||||
 | 
					#define KEY_EQUALS       VK_OEM_PLUS
 | 
				
			||||||
 | 
					#define KEY_MINUS        VK_OEM_MINUS
 | 
				
			||||||
 | 
					#define KEY_PERIOD       VK_OEM_PERIOD
 | 
				
			||||||
 | 
					#define KEY_CAPSLOCK     VK_CAPITAL
 | 
				
			||||||
 | 
					#define KEY_CLEAR        VK_CLEAR
 | 
				
			||||||
 | 
					#define KEY_SPACE        VK_SPACE
 | 
				
			||||||
 | 
					#define KEY_PAUSE        VK_PAUSE
 | 
				
			||||||
 | 
					#define KEY_LSHIFT       VK_LSHIFT
 | 
				
			||||||
 | 
					#define KEY_RSHIFT       VK_RSHIFT
 | 
				
			||||||
 | 
					#define KEY_LCTRL        VK_LCONTROL
 | 
				
			||||||
 | 
					#define KEY_RCTRL        VK_RCONTROL
 | 
				
			||||||
 | 
					#define KEY_LALT         VK_LMENU
 | 
				
			||||||
 | 
					#define KEY_RALT         VK_RMENU
 | 
				
			||||||
 | 
					#define KEY_0            0x30
 | 
				
			||||||
 | 
					#define KEY_1            0x31
 | 
				
			||||||
 | 
					#define KEY_2            0x32
 | 
				
			||||||
 | 
					#define KEY_3            0x33
 | 
				
			||||||
 | 
					#define KEY_4            0x34
 | 
				
			||||||
 | 
					#define KEY_5            0x35
 | 
				
			||||||
 | 
					#define KEY_6            0x36
 | 
				
			||||||
 | 
					#define KEY_7            0x37
 | 
				
			||||||
 | 
					#define KEY_8            0x38
 | 
				
			||||||
 | 
					#define KEY_9            0x39
 | 
				
			||||||
 | 
					#define KEY_a            0x41
 | 
				
			||||||
 | 
					#define KEY_b            0x42
 | 
				
			||||||
 | 
					#define KEY_c            0x43
 | 
				
			||||||
 | 
					#define KEY_d            0x44
 | 
				
			||||||
 | 
					#define KEY_e            0x45
 | 
				
			||||||
 | 
					#define KEY_f            0x46
 | 
				
			||||||
 | 
					#define KEY_g            0x47
 | 
				
			||||||
 | 
					#define KEY_h            0x48
 | 
				
			||||||
 | 
					#define KEY_i            0x49
 | 
				
			||||||
 | 
					#define KEY_j            0x4a
 | 
				
			||||||
 | 
					#define KEY_k            0x4b
 | 
				
			||||||
 | 
					#define KEY_l            0x4c
 | 
				
			||||||
 | 
					#define KEY_m            0x4d
 | 
				
			||||||
 | 
					#define KEY_n            0x4e
 | 
				
			||||||
 | 
					#define KEY_o            0x4f
 | 
				
			||||||
 | 
					#define KEY_p            0x50
 | 
				
			||||||
 | 
					#define KEY_q            0x51
 | 
				
			||||||
 | 
					#define KEY_r            0x52
 | 
				
			||||||
 | 
					#define KEY_s            0x53
 | 
				
			||||||
 | 
					#define KEY_t            0x54
 | 
				
			||||||
 | 
					#define KEY_u            0x55
 | 
				
			||||||
 | 
					#define KEY_v            0x56
 | 
				
			||||||
 | 
					#define KEY_w            0x57
 | 
				
			||||||
 | 
					#define KEY_x            0x58
 | 
				
			||||||
 | 
					#define KEY_y            0x59
 | 
				
			||||||
 | 
					#define KEY_z            0x5a
 | 
				
			||||||
 | 
					#define KEY_KP0          VK_NUMPAD0
 | 
				
			||||||
 | 
					#define KEY_KP1          VK_NUMPAD1
 | 
				
			||||||
 | 
					#define KEY_KP2          VK_NUMPAD2
 | 
				
			||||||
 | 
					#define KEY_KP3          VK_NUMPAD3
 | 
				
			||||||
 | 
					#define KEY_KP4          VK_NUMPAD4
 | 
				
			||||||
 | 
					#define KEY_KP5          VK_NUMPAD5
 | 
				
			||||||
 | 
					#define KEY_KP6          VK_NUMPAD6
 | 
				
			||||||
 | 
					#define KEY_KP7          VK_NUMPAD7
 | 
				
			||||||
 | 
					#define KEY_KP8          VK_NUMPAD8
 | 
				
			||||||
 | 
					#define KEY_KP9          VK_NUMPAD9
 | 
				
			||||||
 | 
					#define KEY_SCROLLOCK    VK_SCROLL
 | 
				
			||||||
 | 
					#define KEY_F1           VK_F1
 | 
				
			||||||
 | 
					#define KEY_F2           VK_F2
 | 
				
			||||||
 | 
					#define KEY_F3           VK_F3
 | 
				
			||||||
 | 
					#define KEY_F4           VK_F4
 | 
				
			||||||
 | 
					#define KEY_F5           VK_F5
 | 
				
			||||||
 | 
					#define KEY_F6           VK_F6
 | 
				
			||||||
 | 
					#define KEY_F7           VK_F7
 | 
				
			||||||
 | 
					#define KEY_F8           VK_F8
 | 
				
			||||||
 | 
					#define KEY_F9           VK_F9
 | 
				
			||||||
 | 
					#define KEY_F10          VK_F10
 | 
				
			||||||
 | 
					#define KEY_F11          VK_F11
 | 
				
			||||||
 | 
					#define KEY_F12          VK_F12
 | 
				
			||||||
 | 
					// end of KEY definitions for win32
 | 
				
			||||||
#else
 | 
					#else
 | 
				
			||||||
// KEY definitions for others
 | 
					// KEY definitions for others
 | 
				
			||||||
#define KEY_UNKNOWN      0
 | 
					#define KEY_UNKNOWN      0
 | 
				
			||||||
 | 
				
			|||||||
@ -18,11 +18,44 @@ keys = ['UNKNOWN',
 | 
				
			|||||||
        'LSHIFT', 'RSHIFT', 'LCTRL', 'RCTRL',
 | 
					        'LSHIFT', 'RSHIFT', 'LCTRL', 'RCTRL',
 | 
				
			||||||
        'LALT', 'RALT']
 | 
					        'LALT', 'RALT']
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def keycode_def(section, key, index, sdl_key=None):
 | 
					win32vk = {
 | 
				
			||||||
 | 
					'BACKSPACE': 'BACK',
 | 
				
			||||||
 | 
					'PAGEUP': 'PRIOR',
 | 
				
			||||||
 | 
					'PAGEDOWN': 'NEXT',
 | 
				
			||||||
 | 
					'CAPSLOCK': 'CAPITAL',
 | 
				
			||||||
 | 
					'EQUALS': 'OEM_PLUS',  # =+ key on US keyboards
 | 
				
			||||||
 | 
					'COMMA': 'OEM_COMMA',
 | 
				
			||||||
 | 
					'MINUS': 'OEM_MINUS',
 | 
				
			||||||
 | 
					'PERIOD': 'OEM_PERIOD',
 | 
				
			||||||
 | 
					'BACKQUOTE': 'OEM_3',
 | 
				
			||||||
 | 
					'LEFTBRACKET': 'OEM_4',
 | 
				
			||||||
 | 
					'RIGHTBRACKET': 'OEM_6',
 | 
				
			||||||
 | 
					'KP_PLUS': 'ADD',
 | 
				
			||||||
 | 
					'KP_MULTIPLY': 'MULTIPLY',
 | 
				
			||||||
 | 
					'KP_MINUS': 'SUBTRACT',
 | 
				
			||||||
 | 
					'KP_DIVIDE': 'DIVIDE',
 | 
				
			||||||
 | 
					'KP_PERIOD': 'DECIMAL',
 | 
				
			||||||
 | 
					'KP_ENTER': 'RETURN',
 | 
				
			||||||
 | 
					'LCTRL': 'LCONTROL',
 | 
				
			||||||
 | 
					'RCTRL': 'RCONTROL',
 | 
				
			||||||
 | 
					'LALT': 'LMENU',
 | 
				
			||||||
 | 
					'RALT': 'RMENU',
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def keycode_def(section, key, index, native_key=None):
 | 
				
			||||||
 | 
						if native_key is None:
 | 
				
			||||||
 | 
							native_key = key
 | 
				
			||||||
	if section == 'SDL and SDL2':
 | 
						if section == 'SDL and SDL2':
 | 
				
			||||||
		if sdl_key is None:
 | 
							return '#define KEY_%-12s K2K(SDLK_%s)\n' % (key, native_key)
 | 
				
			||||||
			sdl_key = key
 | 
						elif section == 'win32':
 | 
				
			||||||
		return '#define KEY_%-12s K2K(SDLK_%s)\n' % (key, sdl_key)
 | 
							if len(key) == 1 and key >= '0' and key <= '9':
 | 
				
			||||||
 | 
								return '#define KEY_%-12s 0x%02x\n' % (key, ord(key))
 | 
				
			||||||
 | 
							elif len(key) == 1 and key >= 'a' and key <= 'z':
 | 
				
			||||||
 | 
								return '#define KEY_%-12s 0x%02x\n' % (key, ord(key)-32)
 | 
				
			||||||
 | 
							elif key == 'UNKNOWN' or key == 'KP_EQUALS':
 | 
				
			||||||
 | 
								return '#define KEY_%-12s 0\n' % (key)
 | 
				
			||||||
 | 
							else:
 | 
				
			||||||
 | 
								return '#define KEY_%-12s VK_%s\n' % (key, native_key)
 | 
				
			||||||
	else:
 | 
						else:
 | 
				
			||||||
		return '#define KEY_%-12s %d\n' % (key, index)
 | 
							return '#define KEY_%-12s %d\n' % (key, index)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -30,7 +63,10 @@ def add_keycodes_defs(section, lines):
 | 
				
			|||||||
	global keys
 | 
						global keys
 | 
				
			||||||
	i = 0
 | 
						i = 0
 | 
				
			||||||
	for key in keys:
 | 
						for key in keys:
 | 
				
			||||||
		lines.append(keycode_def(section, key, i))
 | 
							if section == 'win32' and key in win32vk:
 | 
				
			||||||
 | 
								lines.append(keycode_def(section, key, i, win32vk[key]))
 | 
				
			||||||
 | 
							else:
 | 
				
			||||||
 | 
								lines.append(keycode_def(section, key, i))
 | 
				
			||||||
		i = i + 1
 | 
							i = i + 1
 | 
				
			||||||
	for j in range(10):
 | 
						for j in range(10):
 | 
				
			||||||
		lines.append(keycode_def(section, chr(ord('0') + j), i))
 | 
							lines.append(keycode_def(section, chr(ord('0') + j), i))
 | 
				
			||||||
@ -42,9 +78,15 @@ def add_keycodes_defs(section, lines):
 | 
				
			|||||||
		lines.append('#if defined(USE_SDL)\n')
 | 
							lines.append('#if defined(USE_SDL)\n')
 | 
				
			||||||
	for j in range(10):
 | 
						for j in range(10):
 | 
				
			||||||
		key = "KP%d" % (j)
 | 
							key = "KP%d" % (j)
 | 
				
			||||||
		lines.append(keycode_def(section, key, i))
 | 
							if section == 'win32':
 | 
				
			||||||
 | 
								lines.append(keycode_def(section, key, i, "NUMPAD%d" % (j)))
 | 
				
			||||||
 | 
							else:
 | 
				
			||||||
 | 
								lines.append(keycode_def(section, key, i))
 | 
				
			||||||
		i = i + 1
 | 
							i = i + 1
 | 
				
			||||||
	lines.append(keycode_def(section, 'SCROLLOCK', i))
 | 
						if section == 'win32':
 | 
				
			||||||
 | 
							lines.append(keycode_def(section, 'SCROLLOCK', i, 'SCROLL'))
 | 
				
			||||||
 | 
						else:
 | 
				
			||||||
 | 
							lines.append(keycode_def(section, 'SCROLLOCK', i))
 | 
				
			||||||
	i = i + 1
 | 
						i = i + 1
 | 
				
			||||||
	if section == 'SDL and SDL2':
 | 
						if section == 'SDL and SDL2':
 | 
				
			||||||
		lines.append('#else\n')
 | 
							lines.append('#else\n')
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user