annotate src/video/cocoa/SDL_cocoakeyboard.m @ 2170:243bc7ae5a21

Needed an autorelease pool around the NSText allocation
author Sam Lantinga <slouken@libsdl.org>
date Wed, 11 Jul 2007 14:44:28 +0000
parents 13cf2d5eda86
children 4baee598306d
rev   line source
1931
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1 /*
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2 SDL - Simple DirectMedia Layer
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3 Copyright (C) 1997-2006 Sam Lantinga
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5 This library is free software; you can redistribute it and/or
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
6 modify it under the terms of the GNU Lesser General Public
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
7 License as published by the Free Software Foundation; either
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
8 version 2.1 of the License, or (at your option) any later version.
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
9
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
10 This library is distributed in the hope that it will be useful,
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
13 Lesser General Public License for more details.
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
14
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
15 You should have received a copy of the GNU Lesser General Public
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
16 License along with this library; if not, write to the Free Software
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
18
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
19 Sam Lantinga
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
20 slouken@libsdl.org
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
21 */
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
22 #include "SDL_config.h"
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
23
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
24 #include "SDL_cocoavideo.h"
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
25 #include "SDL_cocoakeys.h"
1931
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
26
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
27 #include "../../events/SDL_keyboard_c.h"
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
28
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
29
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
30 #ifndef NX_DEVICERCTLKEYMASK
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
31 #define NX_DEVICELCTLKEYMASK 0x00000001
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
32 #endif
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
33 #ifndef NX_DEVICELSHIFTKEYMASK
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
34 #define NX_DEVICELSHIFTKEYMASK 0x00000002
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
35 #endif
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
36 #ifndef NX_DEVICERSHIFTKEYMASK
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
37 #define NX_DEVICERSHIFTKEYMASK 0x00000004
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
38 #endif
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
39 #ifndef NX_DEVICELCMDKEYMASK
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
40 #define NX_DEVICELCMDKEYMASK 0x00000008
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
41 #endif
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
42 #ifndef NX_DEVICERCMDKEYMASK
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
43 #define NX_DEVICERCMDKEYMASK 0x00000010
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
44 #endif
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
45 #ifndef NX_DEVICELALTKEYMASK
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
46 #define NX_DEVICELALTKEYMASK 0x00000020
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
47 #endif
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
48 #ifndef NX_DEVICERALTKEYMASK
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
49 #define NX_DEVICERALTKEYMASK 0x00000040
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
50 #endif
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
51 #ifndef NX_DEVICERCTLKEYMASK
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
52 #define NX_DEVICERCTLKEYMASK 0x00002000
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
53 #endif
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
54
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
55 static void
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
56 InitKeymap (SDLKey *keymap)
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
57 {
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
58 const void *KCHRPtr;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
59 UInt32 state;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
60 UInt32 value;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
61 int i;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
62
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
63 for ( i=0; i<256; ++i )
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
64 keymap[i] = SDLK_UNKNOWN;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
65
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
66 /* This keymap is almost exactly the same as the OS 9 one */
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
67 keymap[KEY_ESCAPE] = SDLK_ESCAPE;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
68 keymap[KEY_F1] = SDLK_F1;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
69 keymap[KEY_F2] = SDLK_F2;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
70 keymap[KEY_F3] = SDLK_F3;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
71 keymap[KEY_F4] = SDLK_F4;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
72 keymap[KEY_F5] = SDLK_F5;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
73 keymap[KEY_F6] = SDLK_F6;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
74 keymap[KEY_F7] = SDLK_F7;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
75 keymap[KEY_F8] = SDLK_F8;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
76 keymap[KEY_F9] = SDLK_F9;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
77 keymap[KEY_F10] = SDLK_F10;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
78 keymap[KEY_F11] = SDLK_F11;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
79 keymap[KEY_F12] = SDLK_F12;
2090
f419000e7596 Merged r2975:2976 from branches/SDL-1.2: Mac OS X F13-15 key support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1961
diff changeset
80 keymap[KEY_F13] = SDLK_F13;
f419000e7596 Merged r2975:2976 from branches/SDL-1.2: Mac OS X F13-15 key support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1961
diff changeset
81 keymap[KEY_F14] = SDLK_F14;
f419000e7596 Merged r2975:2976 from branches/SDL-1.2: Mac OS X F13-15 key support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1961
diff changeset
82 keymap[KEY_F15] = SDLK_F15;
f419000e7596 Merged r2975:2976 from branches/SDL-1.2: Mac OS X F13-15 key support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1961
diff changeset
83 /*
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
84 keymap[KEY_PRINT] = SDLK_PRINT;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
85 keymap[KEY_SCROLLOCK] = SDLK_SCROLLOCK;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
86 keymap[KEY_PAUSE] = SDLK_PAUSE;
2090
f419000e7596 Merged r2975:2976 from branches/SDL-1.2: Mac OS X F13-15 key support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1961
diff changeset
87 */
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
88 keymap[KEY_POWER] = SDLK_POWER;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
89 keymap[KEY_BACKQUOTE] = SDLK_BACKQUOTE;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
90 keymap[KEY_1] = SDLK_1;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
91 keymap[KEY_2] = SDLK_2;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
92 keymap[KEY_3] = SDLK_3;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
93 keymap[KEY_4] = SDLK_4;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
94 keymap[KEY_5] = SDLK_5;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
95 keymap[KEY_6] = SDLK_6;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
96 keymap[KEY_7] = SDLK_7;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
97 keymap[KEY_8] = SDLK_8;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
98 keymap[KEY_9] = SDLK_9;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
99 keymap[KEY_0] = SDLK_0;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
100 keymap[KEY_MINUS] = SDLK_MINUS;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
101 keymap[KEY_EQUALS] = SDLK_EQUALS;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
102 keymap[KEY_BACKSPACE] = SDLK_BACKSPACE;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
103 keymap[KEY_INSERT] = SDLK_INSERT;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
104 keymap[KEY_HOME] = SDLK_HOME;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
105 keymap[KEY_PAGEUP] = SDLK_PAGEUP;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
106 keymap[KEY_NUMLOCK] = SDLK_NUMLOCK;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
107 keymap[KEY_KP_EQUALS] = SDLK_KP_EQUALS;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
108 keymap[KEY_KP_DIVIDE] = SDLK_KP_DIVIDE;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
109 keymap[KEY_KP_MULTIPLY] = SDLK_KP_MULTIPLY;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
110 keymap[KEY_TAB] = SDLK_TAB;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
111 keymap[KEY_q] = SDLK_q;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
112 keymap[KEY_w] = SDLK_w;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
113 keymap[KEY_e] = SDLK_e;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
114 keymap[KEY_r] = SDLK_r;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
115 keymap[KEY_t] = SDLK_t;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
116 keymap[KEY_y] = SDLK_y;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
117 keymap[KEY_u] = SDLK_u;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
118 keymap[KEY_i] = SDLK_i;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
119 keymap[KEY_o] = SDLK_o;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
120 keymap[KEY_p] = SDLK_p;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
121 keymap[KEY_LEFTBRACKET] = SDLK_LEFTBRACKET;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
122 keymap[KEY_RIGHTBRACKET] = SDLK_RIGHTBRACKET;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
123 keymap[KEY_BACKSLASH] = SDLK_BACKSLASH;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
124 keymap[KEY_DELETE] = SDLK_DELETE;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
125 keymap[KEY_END] = SDLK_END;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
126 keymap[KEY_PAGEDOWN] = SDLK_PAGEDOWN;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
127 keymap[KEY_KP7] = SDLK_KP7;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
128 keymap[KEY_KP8] = SDLK_KP8;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
129 keymap[KEY_KP9] = SDLK_KP9;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
130 keymap[KEY_KP_MINUS] = SDLK_KP_MINUS;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
131 keymap[KEY_CAPSLOCK] = SDLK_CAPSLOCK;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
132 keymap[KEY_a] = SDLK_a;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
133 keymap[KEY_s] = SDLK_s;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
134 keymap[KEY_d] = SDLK_d;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
135 keymap[KEY_f] = SDLK_f;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
136 keymap[KEY_g] = SDLK_g;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
137 keymap[KEY_h] = SDLK_h;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
138 keymap[KEY_j] = SDLK_j;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
139 keymap[KEY_k] = SDLK_k;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
140 keymap[KEY_l] = SDLK_l;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
141 keymap[KEY_SEMICOLON] = SDLK_SEMICOLON;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
142 keymap[KEY_QUOTE] = SDLK_QUOTE;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
143 keymap[KEY_RETURN] = SDLK_RETURN;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
144 keymap[KEY_KP4] = SDLK_KP4;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
145 keymap[KEY_KP5] = SDLK_KP5;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
146 keymap[KEY_KP6] = SDLK_KP6;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
147 keymap[KEY_KP_PLUS] = SDLK_KP_PLUS;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
148 keymap[KEY_LSHIFT] = SDLK_LSHIFT;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
149 keymap[KEY_RSHIFT] = SDLK_RSHIFT;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
150 keymap[KEY_z] = SDLK_z;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
151 keymap[KEY_x] = SDLK_x;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
152 keymap[KEY_c] = SDLK_c;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
153 keymap[KEY_v] = SDLK_v;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
154 keymap[KEY_b] = SDLK_b;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
155 keymap[KEY_n] = SDLK_n;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
156 keymap[KEY_m] = SDLK_m;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
157 keymap[KEY_COMMA] = SDLK_COMMA;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
158 keymap[KEY_PERIOD] = SDLK_PERIOD;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
159 keymap[KEY_SLASH] = SDLK_SLASH;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
160 keymap[KEY_UP] = SDLK_UP;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
161 keymap[KEY_KP1] = SDLK_KP1;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
162 keymap[KEY_KP2] = SDLK_KP2;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
163 keymap[KEY_KP3] = SDLK_KP3;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
164 keymap[KEY_KP_ENTER] = SDLK_KP_ENTER;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
165 keymap[KEY_LCTRL] = SDLK_LCTRL;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
166 keymap[KEY_LALT] = SDLK_LALT;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
167 keymap[KEY_LMETA] = SDLK_LMETA;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
168 keymap[KEY_RCTRL] = SDLK_RCTRL;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
169 keymap[KEY_RALT] = SDLK_RALT;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
170 keymap[KEY_RMETA] = SDLK_RMETA;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
171 keymap[KEY_SPACE] = SDLK_SPACE;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
172 keymap[KEY_LEFT] = SDLK_LEFT;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
173 keymap[KEY_DOWN] = SDLK_DOWN;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
174 keymap[KEY_RIGHT] = SDLK_RIGHT;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
175 keymap[KEY_KP0] = SDLK_KP0;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
176 keymap[KEY_KP_PERIOD] = SDLK_KP_PERIOD;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
177 keymap[KEY_IBOOK_ENTER] = SDLK_KP_ENTER;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
178 keymap[KEY_IBOOK_RIGHT] = SDLK_RIGHT;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
179 keymap[KEY_IBOOK_DOWN] = SDLK_DOWN;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
180 keymap[KEY_IBOOK_UP] = SDLK_UP;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
181 keymap[KEY_IBOOK_LEFT] = SDLK_LEFT;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
182
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
183 /*
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
184 Up there we setup a static scancode->keysym map. However, it will not
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
185 work very well on international keyboard. Hence we now query Mac OS X
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
186 for its own keymap to adjust our own mapping table. However, this is
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
187 basically only useful for ascii char keys. This is also the reason
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
188 why we keep the static table, too.
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
189 */
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
190
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
191 /* Get a pointer to the systems cached KCHR */
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
192 KCHRPtr = (void *)GetScriptManagerVariable(smKCHRCache);
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
193 if (KCHRPtr) {
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
194 /* Loop over all 127 possible scan codes */
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
195 for (i = 0; i < 0x7F; i++) {
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
196 /* We pretend a clean start to begin with (i.e. no dead keys active */
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
197 state = 0;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
198
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
199 /* Now translate the key code to a key value */
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
200 value = KeyTranslate(KCHRPtr, i, &state) & 0xff;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
201
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
202 /* If the state become 0, it was a dead key. We need to translate again,
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
203 passing in the new state, to get the actual key value */
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
204 if (state != 0)
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
205 value = KeyTranslate(KCHRPtr, i, &state) & 0xff;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
206
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
207 /* Now we should have a latin1 value, which are SDL keysyms */
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
208 if (value >= 32 && value <= 255) {
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
209 keymap[i] = value;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
210 }
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
211 }
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
212 }
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
213
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
214 /*
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
215 The keypad codes are re-setup here, because the loop above cannot
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
216 distinguish between a key on the keypad and a regular key. We maybe
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
217 could get around this problem in another fashion: NSEvent's flags
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
218 include a "NSNumericPadKeyMask" bit; we could check that and modify
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
219 the symbol we return on the fly. However, this flag seems to exhibit
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
220 some weird behaviour related to the num lock key
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
221 */
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
222 keymap[KEY_KP0] = SDLK_KP0;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
223 keymap[KEY_KP1] = SDLK_KP1;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
224 keymap[KEY_KP2] = SDLK_KP2;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
225 keymap[KEY_KP3] = SDLK_KP3;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
226 keymap[KEY_KP4] = SDLK_KP4;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
227 keymap[KEY_KP5] = SDLK_KP5;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
228 keymap[KEY_KP6] = SDLK_KP6;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
229 keymap[KEY_KP7] = SDLK_KP7;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
230 keymap[KEY_KP8] = SDLK_KP8;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
231 keymap[KEY_KP9] = SDLK_KP9;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
232 keymap[KEY_KP_MINUS] = SDLK_KP_MINUS;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
233 keymap[KEY_KP_PLUS] = SDLK_KP_PLUS;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
234 keymap[KEY_KP_PERIOD] = SDLK_KP_PERIOD;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
235 keymap[KEY_KP_EQUALS] = SDLK_KP_EQUALS;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
236 keymap[KEY_KP_DIVIDE] = SDLK_KP_DIVIDE;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
237 keymap[KEY_KP_MULTIPLY] = SDLK_KP_MULTIPLY;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
238 keymap[KEY_KP_ENTER] = SDLK_KP_ENTER;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
239 }
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
240
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
241 /* This is the original behavior, before support was added for
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
242 * differentiating between left and right versions of the keys.
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
243 */
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
244 static void
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
245 DoUnsidedModifiers(int keyboard, unsigned short scancode,
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
246 unsigned int oldMods, unsigned int newMods)
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
247 {
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
248 const int mapping[] = { SDLK_CAPSLOCK, SDLK_LSHIFT, SDLK_LCTRL, SDLK_LALT, SDLK_LMETA };
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
249 unsigned int i, bit;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
250
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
251 /* Iterate through the bits, testing each against the current modifiers */
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
252 for (i = 0, bit = NSAlphaShiftKeyMask; bit <= NSCommandKeyMask; bit <<= 1, ++i) {
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
253 unsigned int oldMask, newMask;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
254
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
255 oldMask = oldMods & bit;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
256 newMask = newMods & bit;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
257
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
258 if (oldMask && oldMask != newMask) { /* modifier up event */
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
259 /* If this was Caps Lock, we need some additional voodoo to make SDL happy */
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
260 if (bit == NSAlphaShiftKeyMask) {
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
261 SDL_SendKeyboardKey(keyboard, SDL_PRESSED, (Uint8)scancode, mapping[i]);
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
262 }
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
263 SDL_SendKeyboardKey(keyboard, SDL_RELEASED, (Uint8)scancode, mapping[i]);
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
264 } else if (newMask && oldMask != newMask) { /* modifier down event */
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
265 SDL_SendKeyboardKey(keyboard, SDL_PRESSED, (Uint8)scancode, mapping[i]);
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
266 /* If this was Caps Lock, we need some additional voodoo to make SDL happy */
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
267 if (bit == NSAlphaShiftKeyMask) {
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
268 SDL_SendKeyboardKey(keyboard, SDL_RELEASED, (Uint8)scancode, mapping[i]);
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
269 }
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
270 }
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
271 }
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
272 }
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
273
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
274 /* This is a helper function for HandleModifierSide. This
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
275 * function reverts back to behavior before the distinction between
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
276 * sides was made.
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
277 */
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
278 static void
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
279 HandleNonDeviceModifier(int keyboard, unsigned short scancode,
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
280 unsigned int device_independent_mask,
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
281 unsigned int oldMods,
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
282 unsigned int newMods,
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
283 SDLKey key_sym)
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
284 {
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
285 unsigned int oldMask, newMask;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
286
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
287 /* Isolate just the bits we care about in the depedent bits so we can
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
288 * figure out what changed
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
289 */
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
290 oldMask = oldMods & device_independent_mask;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
291 newMask = newMods & device_independent_mask;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
292
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
293 if (oldMask && oldMask != newMask) {
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
294 SDL_SendKeyboardKey(keyboard, SDL_RELEASED, (Uint8)scancode, key_sym);
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
295 } else if (newMask && oldMask != newMask) {
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
296 SDL_SendKeyboardKey(keyboard, SDL_PRESSED, (Uint8)scancode, key_sym);
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
297 }
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
298 }
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
299
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
300 /* This is a helper function for HandleModifierSide.
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
301 * This function sets the actual SDL_PrivateKeyboard event.
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
302 */
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
303 static void
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
304 HandleModifierOneSide(int keyboard, unsigned short scancode,
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
305 unsigned int oldMods, unsigned int newMods,
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
306 SDLKey key_sym,
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
307 unsigned int sided_device_dependent_mask)
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
308 {
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
309 unsigned int old_dep_mask, new_dep_mask;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
310
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
311 /* Isolate just the bits we care about in the depedent bits so we can
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
312 * figure out what changed
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
313 */
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
314 old_dep_mask = oldMods & sided_device_dependent_mask;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
315 new_dep_mask = newMods & sided_device_dependent_mask;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
316
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
317 /* We now know that this side bit flipped. But we don't know if
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
318 * it went pressed to released or released to pressed, so we must
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
319 * find out which it is.
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
320 */
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
321 if (new_dep_mask && old_dep_mask != new_dep_mask) {
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
322 SDL_SendKeyboardKey(keyboard, SDL_PRESSED, (Uint8)scancode, key_sym);
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
323 } else {
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
324 SDL_SendKeyboardKey(keyboard, SDL_RELEASED, (Uint8)scancode, key_sym);
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
325 }
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
326 }
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
327
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
328 /* This is a helper function for DoSidedModifiers.
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
329 * This function will figure out if the modifier key is the left or right side,
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
330 * e.g. left-shift vs right-shift.
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
331 */
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
332 static void
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
333 HandleModifierSide(int keyboard, unsigned short scancode,
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
334 int device_independent_mask,
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
335 unsigned int oldMods, unsigned int newMods,
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
336 SDLKey left_key_sym,
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
337 SDLKey right_key_sym,
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
338 unsigned int left_device_dependent_mask,
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
339 unsigned int right_device_dependent_mask)
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
340 {
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
341 unsigned int device_dependent_mask = (left_device_dependent_mask |
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
342 right_device_dependent_mask);
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
343 unsigned int diff_mod;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
344
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
345 /* On the basis that the device independent mask is set, but there are
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
346 * no device dependent flags set, we'll assume that we can't detect this
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
347 * keyboard and revert to the unsided behavior.
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
348 */
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
349 if ((device_dependent_mask & newMods) == 0) {
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
350 /* Revert to the old behavior */
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
351 HandleNonDeviceModifier(keyboard, scancode, device_independent_mask, oldMods, newMods, left_key_sym);
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
352 return;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
353 }
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
354
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
355 /* XOR the previous state against the new state to see if there's a change */
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
356 diff_mod = (device_dependent_mask & oldMods) ^
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
357 (device_dependent_mask & newMods);
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
358 if (diff_mod) {
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
359 /* A change in state was found. Isolate the left and right bits
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
360 * to handle them separately just in case the values can simulataneously
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
361 * change or if the bits don't both exist.
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
362 */
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
363 if (left_device_dependent_mask & diff_mod) {
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
364 HandleModifierOneSide(keyboard, scancode, oldMods, newMods, left_key_sym, left_device_dependent_mask);
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
365 }
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
366 if (right_device_dependent_mask & diff_mod) {
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
367 HandleModifierOneSide(keyboard, scancode, oldMods, newMods, right_key_sym, right_device_dependent_mask);
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
368 }
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
369 }
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
370 }
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
371
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
372 /* This is a helper function for DoSidedModifiers.
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
373 * This function will release a key press in the case that
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
374 * it is clear that the modifier has been released (i.e. one side
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
375 * can't still be down).
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
376 */
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
377 static void
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
378 ReleaseModifierSide(int keyboard, unsigned short scancode,
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
379 unsigned int device_independent_mask,
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
380 unsigned int oldMods, unsigned int newMods,
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
381 SDLKey left_key_sym,
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
382 SDLKey right_key_sym,
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
383 unsigned int left_device_dependent_mask,
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
384 unsigned int right_device_dependent_mask)
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
385 {
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
386 unsigned int device_dependent_mask = (left_device_dependent_mask |
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
387 right_device_dependent_mask);
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
388
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
389 /* On the basis that the device independent mask is set, but there are
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
390 * no device dependent flags set, we'll assume that we can't detect this
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
391 * keyboard and revert to the unsided behavior.
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
392 */
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
393 if ((device_dependent_mask & oldMods) == 0) {
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
394 /* In this case, we can't detect the keyboard, so use the left side
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
395 * to represent both, and release it.
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
396 */
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
397 SDL_SendKeyboardKey(keyboard, SDL_RELEASED, (Uint8)scancode, left_key_sym);
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
398 return;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
399 }
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
400
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
401 /*
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
402 * This could have been done in an if-else case because at this point,
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
403 * we know that all keys have been released when calling this function.
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
404 * But I'm being paranoid so I want to handle each separately,
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
405 * so I hope this doesn't cause other problems.
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
406 */
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
407 if ( left_device_dependent_mask & oldMods ) {
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
408 SDL_SendKeyboardKey(keyboard, SDL_RELEASED, (Uint8)scancode, left_key_sym);
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
409 }
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
410 if ( right_device_dependent_mask & oldMods ) {
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
411 SDL_SendKeyboardKey(keyboard, SDL_RELEASED, (Uint8)scancode, right_key_sym);
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
412 }
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
413 }
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
414
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
415 /* This is a helper function for DoSidedModifiers.
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
416 * This function handles the CapsLock case.
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
417 */
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
418 static void
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
419 HandleCapsLock(int keyboard, unsigned short scancode,
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
420 unsigned int oldMods, unsigned int newMods)
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
421 {
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
422 unsigned int oldMask, newMask;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
423
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
424 oldMask = oldMods & NSAlphaShiftKeyMask;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
425 newMask = newMods & NSAlphaShiftKeyMask;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
426
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
427 if (oldMask != newMask) {
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
428 SDL_SendKeyboardKey(keyboard, SDL_PRESSED, (Uint8)scancode, SDLK_CAPSLOCK);
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
429 SDL_SendKeyboardKey(keyboard, SDL_RELEASED, (Uint8)scancode, SDLK_CAPSLOCK);
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
430 }
1960
118daa3a24cc Added numlock support
Sam Lantinga <slouken@libsdl.org>
parents: 1959
diff changeset
431
118daa3a24cc Added numlock support
Sam Lantinga <slouken@libsdl.org>
parents: 1959
diff changeset
432 oldMask = oldMods & NSNumericPadKeyMask;
118daa3a24cc Added numlock support
Sam Lantinga <slouken@libsdl.org>
parents: 1959
diff changeset
433 newMask = newMods & NSNumericPadKeyMask;
118daa3a24cc Added numlock support
Sam Lantinga <slouken@libsdl.org>
parents: 1959
diff changeset
434
118daa3a24cc Added numlock support
Sam Lantinga <slouken@libsdl.org>
parents: 1959
diff changeset
435 if (oldMask != newMask) {
118daa3a24cc Added numlock support
Sam Lantinga <slouken@libsdl.org>
parents: 1959
diff changeset
436 SDL_SendKeyboardKey(keyboard, SDL_PRESSED, (Uint8)scancode, SDLK_NUMLOCK);
118daa3a24cc Added numlock support
Sam Lantinga <slouken@libsdl.org>
parents: 1959
diff changeset
437 SDL_SendKeyboardKey(keyboard, SDL_RELEASED, (Uint8)scancode, SDLK_NUMLOCK);
118daa3a24cc Added numlock support
Sam Lantinga <slouken@libsdl.org>
parents: 1959
diff changeset
438 }
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
439 }
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
440
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
441 /* This function will handle the modifier keys and also determine the
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
442 * correct side of the key.
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
443 */
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
444 static void
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
445 DoSidedModifiers(int keyboard, unsigned short scancode,
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
446 unsigned int oldMods, unsigned int newMods)
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
447 {
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
448 /* Set up arrays for the key syms for the left and right side. */
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
449 const SDLKey left_mapping[] = { SDLK_LSHIFT, SDLK_LCTRL, SDLK_LALT, SDLK_LMETA };
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
450 const SDLKey right_mapping[] = { SDLK_RSHIFT, SDLK_RCTRL, SDLK_RALT, SDLK_RMETA };
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
451 /* Set up arrays for the device dependent masks with indices that
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
452 * correspond to the _mapping arrays
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
453 */
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
454 const unsigned int left_device_mapping[] = { NX_DEVICELSHIFTKEYMASK, NX_DEVICELCTLKEYMASK, NX_DEVICELALTKEYMASK, NX_DEVICELCMDKEYMASK };
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
455 const unsigned int right_device_mapping[] = { NX_DEVICERSHIFTKEYMASK, NX_DEVICERCTLKEYMASK, NX_DEVICERALTKEYMASK, NX_DEVICERCMDKEYMASK };
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
456
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
457 unsigned int i, bit;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
458
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
459 /* Handle CAPSLOCK separately because it doesn't have a left/right side */
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
460 HandleCapsLock(keyboard, scancode, oldMods, newMods);
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
461
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
462 /* Iterate through the bits, testing each against the old modifiers */
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
463 for (i = 0, bit = NSShiftKeyMask; bit <= NSCommandKeyMask; bit <<= 1, ++i) {
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
464 unsigned int oldMask, newMask;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
465
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
466 oldMask = oldMods & bit;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
467 newMask = newMods & bit;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
468
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
469 /* If the bit is set, we must always examine it because the left
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
470 * and right side keys may alternate or both may be pressed.
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
471 */
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
472 if (newMask) {
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
473 HandleModifierSide(keyboard, scancode, bit, oldMods, newMods,
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
474 left_mapping[i], right_mapping[i],
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
475 left_device_mapping[i], right_device_mapping[i]);
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
476 }
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
477 /* If the state changed from pressed to unpressed, we must examine
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
478 * the device dependent bits to release the correct keys.
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
479 */
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
480 else if (oldMask && oldMask != newMask) {
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
481 ReleaseModifierSide(keyboard, scancode, bit, oldMods, newMods,
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
482 left_mapping[i], right_mapping[i],
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
483 left_device_mapping[i], right_device_mapping[i]);
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
484 }
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
485 }
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
486 }
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
487
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
488 static void
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
489 HandleModifiers(_THIS, unsigned short scancode, unsigned int modifierFlags)
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
490 {
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
491 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
492
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
493 if (modifierFlags == data->modifierFlags) {
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
494 return;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
495 }
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
496
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
497 /*
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
498 * Starting with Panther (10.3.0), the ability to distinguish between
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
499 * left side and right side modifiers is available.
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
500 */
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
501 if (data->osversion >= 0x1030) {
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
502 DoSidedModifiers(data->keyboard, scancode, data->modifierFlags, modifierFlags);
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
503 } else {
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
504 DoUnsidedModifiers(data->keyboard, scancode, data->modifierFlags, modifierFlags);
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
505 }
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
506 data->modifierFlags = modifierFlags;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
507 }
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
508
1931
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
509 void
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
510 Cocoa_InitKeyboard(_THIS)
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
511 {
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
512 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
513 SDL_Keyboard keyboard;
2170
243bc7ae5a21 Needed an autorelease pool around the NSText allocation
Sam Lantinga <slouken@libsdl.org>
parents: 2169
diff changeset
514 NSAutoreleasePool *pool;
1931
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
515
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
516 InitKeymap(data->keymap);
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
517
2170
243bc7ae5a21 Needed an autorelease pool around the NSText allocation
Sam Lantinga <slouken@libsdl.org>
parents: 2169
diff changeset
518 pool = [[NSAutoreleasePool alloc] init];
2169
13cf2d5eda86 Added key composition support, courtesy of Kuon
Sam Lantinga <slouken@libsdl.org>
parents: 2129
diff changeset
519 data->fieldEdit = [[NSTextView alloc] initWithFrame:NSMakeRect(0.0, 0.0, 0.0, 0.0)];
2170
243bc7ae5a21 Needed an autorelease pool around the NSText allocation
Sam Lantinga <slouken@libsdl.org>
parents: 2169
diff changeset
520 [pool release];
2169
13cf2d5eda86 Added key composition support, courtesy of Kuon
Sam Lantinga <slouken@libsdl.org>
parents: 2129
diff changeset
521
1931
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
522 SDL_zero(keyboard);
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
523 data->keyboard = SDL_AddKeyboard(&keyboard, -1);
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
524 }
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
525
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
526 void
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
527 Cocoa_HandleKeyEvent(_THIS, NSEvent *event)
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
528 {
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
529 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
530 unsigned short scancode = [event keyCode];
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
531 const char *text;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
532
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
533 if (scancode >= 256) {
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
534 /* Hmm, does this ever happen? If so, need to extend the keymap... */
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
535 return;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
536 }
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
537
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
538 switch ([event type]) {
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
539 case NSKeyDown:
2129
047245361002 Key repeat is handled by the OS, since text input is now decoupled from physical key events.
Sam Lantinga <slouken@libsdl.org>
parents: 2090
diff changeset
540 if (![event isARepeat]) {
047245361002 Key repeat is handled by the OS, since text input is now decoupled from physical key events.
Sam Lantinga <slouken@libsdl.org>
parents: 2090
diff changeset
541 SDL_SendKeyboardKey(data->keyboard, SDL_PRESSED, (Uint8)scancode,
047245361002 Key repeat is handled by the OS, since text input is now decoupled from physical key events.
Sam Lantinga <slouken@libsdl.org>
parents: 2090
diff changeset
542 data->keymap[scancode]);
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
543 }
2129
047245361002 Key repeat is handled by the OS, since text input is now decoupled from physical key events.
Sam Lantinga <slouken@libsdl.org>
parents: 2090
diff changeset
544 if (SDL_EventState(SDL_TEXTINPUT, SDL_QUERY)) {
2169
13cf2d5eda86 Added key composition support, courtesy of Kuon
Sam Lantinga <slouken@libsdl.org>
parents: 2129
diff changeset
545 [data->fieldEdit interpretKeyEvents:[NSArray arrayWithObject:event]];
2129
047245361002 Key repeat is handled by the OS, since text input is now decoupled from physical key events.
Sam Lantinga <slouken@libsdl.org>
parents: 2090
diff changeset
546 text = [[event characters] UTF8String];
047245361002 Key repeat is handled by the OS, since text input is now decoupled from physical key events.
Sam Lantinga <slouken@libsdl.org>
parents: 2090
diff changeset
547 if(text && *text) {
047245361002 Key repeat is handled by the OS, since text input is now decoupled from physical key events.
Sam Lantinga <slouken@libsdl.org>
parents: 2090
diff changeset
548 SDL_SendKeyboardText(data->keyboard, text);
047245361002 Key repeat is handled by the OS, since text input is now decoupled from physical key events.
Sam Lantinga <slouken@libsdl.org>
parents: 2090
diff changeset
549 }
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
550 }
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
551 break;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
552 case NSKeyUp:
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
553 SDL_SendKeyboardKey(data->keyboard, SDL_RELEASED, (Uint8)scancode,
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
554 data->keymap[scancode]);
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
555 break;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
556 case NSFlagsChanged:
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
557 HandleModifiers(_this, scancode, [event modifierFlags]);
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
558 break;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
559 }
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
560 }
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
561
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
562 void
1931
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
563 Cocoa_QuitKeyboard(_THIS)
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
564 {
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
565 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
566
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
567 SDL_DelKeyboard(data->keyboard);
2169
13cf2d5eda86 Added key composition support, courtesy of Kuon
Sam Lantinga <slouken@libsdl.org>
parents: 2129
diff changeset
568
13cf2d5eda86 Added key composition support, courtesy of Kuon
Sam Lantinga <slouken@libsdl.org>
parents: 2129
diff changeset
569 [data->fieldEdit release];
1931
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
570 }
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
571
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
572 /* vi: set ts=4 sw=4 expandtab: */