annotate src/video/cocoa/SDL_cocoakeyboard.m @ 2035:c848c18684ab

Started update for 1.3
author Patrice Mandin <patmandin@gmail.com>
date Wed, 20 Sep 2006 22:09:19 +0000
parents f42f10fc309e
children f419000e7596
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;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
80 keymap[KEY_PRINT] = SDLK_PRINT;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
81 keymap[KEY_SCROLLOCK] = SDLK_SCROLLOCK;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
82 keymap[KEY_PAUSE] = SDLK_PAUSE;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
83 keymap[KEY_POWER] = SDLK_POWER;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
84 keymap[KEY_BACKQUOTE] = SDLK_BACKQUOTE;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
85 keymap[KEY_1] = SDLK_1;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
86 keymap[KEY_2] = SDLK_2;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
87 keymap[KEY_3] = SDLK_3;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
88 keymap[KEY_4] = SDLK_4;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
89 keymap[KEY_5] = SDLK_5;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
90 keymap[KEY_6] = SDLK_6;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
91 keymap[KEY_7] = SDLK_7;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
92 keymap[KEY_8] = SDLK_8;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
93 keymap[KEY_9] = SDLK_9;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
94 keymap[KEY_0] = SDLK_0;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
95 keymap[KEY_MINUS] = SDLK_MINUS;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
96 keymap[KEY_EQUALS] = SDLK_EQUALS;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
97 keymap[KEY_BACKSPACE] = SDLK_BACKSPACE;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
98 keymap[KEY_INSERT] = SDLK_INSERT;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
99 keymap[KEY_HOME] = SDLK_HOME;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
100 keymap[KEY_PAGEUP] = SDLK_PAGEUP;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
101 keymap[KEY_NUMLOCK] = SDLK_NUMLOCK;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
102 keymap[KEY_KP_EQUALS] = SDLK_KP_EQUALS;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
103 keymap[KEY_KP_DIVIDE] = SDLK_KP_DIVIDE;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
104 keymap[KEY_KP_MULTIPLY] = SDLK_KP_MULTIPLY;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
105 keymap[KEY_TAB] = SDLK_TAB;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
106 keymap[KEY_q] = SDLK_q;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
107 keymap[KEY_w] = SDLK_w;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
108 keymap[KEY_e] = SDLK_e;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
109 keymap[KEY_r] = SDLK_r;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
110 keymap[KEY_t] = SDLK_t;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
111 keymap[KEY_y] = SDLK_y;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
112 keymap[KEY_u] = SDLK_u;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
113 keymap[KEY_i] = SDLK_i;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
114 keymap[KEY_o] = SDLK_o;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
115 keymap[KEY_p] = SDLK_p;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
116 keymap[KEY_LEFTBRACKET] = SDLK_LEFTBRACKET;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
117 keymap[KEY_RIGHTBRACKET] = SDLK_RIGHTBRACKET;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
118 keymap[KEY_BACKSLASH] = SDLK_BACKSLASH;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
119 keymap[KEY_DELETE] = SDLK_DELETE;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
120 keymap[KEY_END] = SDLK_END;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
121 keymap[KEY_PAGEDOWN] = SDLK_PAGEDOWN;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
122 keymap[KEY_KP7] = SDLK_KP7;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
123 keymap[KEY_KP8] = SDLK_KP8;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
124 keymap[KEY_KP9] = SDLK_KP9;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
125 keymap[KEY_KP_MINUS] = SDLK_KP_MINUS;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
126 keymap[KEY_CAPSLOCK] = SDLK_CAPSLOCK;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
127 keymap[KEY_a] = SDLK_a;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
128 keymap[KEY_s] = SDLK_s;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
129 keymap[KEY_d] = SDLK_d;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
130 keymap[KEY_f] = SDLK_f;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
131 keymap[KEY_g] = SDLK_g;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
132 keymap[KEY_h] = SDLK_h;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
133 keymap[KEY_j] = SDLK_j;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
134 keymap[KEY_k] = SDLK_k;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
135 keymap[KEY_l] = SDLK_l;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
136 keymap[KEY_SEMICOLON] = SDLK_SEMICOLON;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
137 keymap[KEY_QUOTE] = SDLK_QUOTE;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
138 keymap[KEY_RETURN] = SDLK_RETURN;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
139 keymap[KEY_KP4] = SDLK_KP4;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
140 keymap[KEY_KP5] = SDLK_KP5;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
141 keymap[KEY_KP6] = SDLK_KP6;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
142 keymap[KEY_KP_PLUS] = SDLK_KP_PLUS;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
143 keymap[KEY_LSHIFT] = SDLK_LSHIFT;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
144 keymap[KEY_RSHIFT] = SDLK_RSHIFT;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
145 keymap[KEY_z] = SDLK_z;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
146 keymap[KEY_x] = SDLK_x;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
147 keymap[KEY_c] = SDLK_c;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
148 keymap[KEY_v] = SDLK_v;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
149 keymap[KEY_b] = SDLK_b;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
150 keymap[KEY_n] = SDLK_n;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
151 keymap[KEY_m] = SDLK_m;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
152 keymap[KEY_COMMA] = SDLK_COMMA;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
153 keymap[KEY_PERIOD] = SDLK_PERIOD;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
154 keymap[KEY_SLASH] = SDLK_SLASH;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
155 keymap[KEY_UP] = SDLK_UP;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
156 keymap[KEY_KP1] = SDLK_KP1;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
157 keymap[KEY_KP2] = SDLK_KP2;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
158 keymap[KEY_KP3] = SDLK_KP3;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
159 keymap[KEY_KP_ENTER] = SDLK_KP_ENTER;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
160 keymap[KEY_LCTRL] = SDLK_LCTRL;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
161 keymap[KEY_LALT] = SDLK_LALT;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
162 keymap[KEY_LMETA] = SDLK_LMETA;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
163 keymap[KEY_RCTRL] = SDLK_RCTRL;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
164 keymap[KEY_RALT] = SDLK_RALT;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
165 keymap[KEY_RMETA] = SDLK_RMETA;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
166 keymap[KEY_SPACE] = SDLK_SPACE;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
167 keymap[KEY_LEFT] = SDLK_LEFT;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
168 keymap[KEY_DOWN] = SDLK_DOWN;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
169 keymap[KEY_RIGHT] = SDLK_RIGHT;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
170 keymap[KEY_KP0] = SDLK_KP0;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
171 keymap[KEY_KP_PERIOD] = SDLK_KP_PERIOD;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
172 keymap[KEY_IBOOK_ENTER] = SDLK_KP_ENTER;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
173 keymap[KEY_IBOOK_RIGHT] = SDLK_RIGHT;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
174 keymap[KEY_IBOOK_DOWN] = SDLK_DOWN;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
175 keymap[KEY_IBOOK_UP] = SDLK_UP;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
176 keymap[KEY_IBOOK_LEFT] = SDLK_LEFT;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
177
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
178 /*
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
179 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
180 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
181 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
182 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
183 why we keep the static table, too.
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
184 */
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
185
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
186 /* Get a pointer to the systems cached KCHR */
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
187 KCHRPtr = (void *)GetScriptManagerVariable(smKCHRCache);
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
188 if (KCHRPtr) {
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
189 /* Loop over all 127 possible scan codes */
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
190 for (i = 0; i < 0x7F; i++) {
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
191 /* 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
192 state = 0;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
193
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
194 /* Now translate the key code to a key value */
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
195 value = KeyTranslate(KCHRPtr, i, &state) & 0xff;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
196
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
197 /* 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
198 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
199 if (state != 0)
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 /* 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
203 if (value >= 32 && value <= 255) {
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
204 keymap[i] = value;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
205 }
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 }
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
208
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
209 /*
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
210 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
211 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
212 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
213 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
214 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
215 some weird behaviour related to the num lock key
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
216 */
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
217 keymap[KEY_KP0] = SDLK_KP0;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
218 keymap[KEY_KP1] = SDLK_KP1;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
219 keymap[KEY_KP2] = SDLK_KP2;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
220 keymap[KEY_KP3] = SDLK_KP3;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
221 keymap[KEY_KP4] = SDLK_KP4;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
222 keymap[KEY_KP5] = SDLK_KP5;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
223 keymap[KEY_KP6] = SDLK_KP6;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
224 keymap[KEY_KP7] = SDLK_KP7;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
225 keymap[KEY_KP8] = SDLK_KP8;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
226 keymap[KEY_KP9] = SDLK_KP9;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
227 keymap[KEY_KP_MINUS] = SDLK_KP_MINUS;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
228 keymap[KEY_KP_PLUS] = SDLK_KP_PLUS;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
229 keymap[KEY_KP_PERIOD] = SDLK_KP_PERIOD;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
230 keymap[KEY_KP_EQUALS] = SDLK_KP_EQUALS;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
231 keymap[KEY_KP_DIVIDE] = SDLK_KP_DIVIDE;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
232 keymap[KEY_KP_MULTIPLY] = SDLK_KP_MULTIPLY;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
233 keymap[KEY_KP_ENTER] = SDLK_KP_ENTER;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
234 }
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
235
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
236 /* 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
237 * differentiating between left and right versions of the keys.
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
238 */
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
239 static void
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
240 DoUnsidedModifiers(int keyboard, unsigned short scancode,
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
241 unsigned int oldMods, unsigned int newMods)
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
242 {
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
243 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
244 unsigned int i, bit;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
245
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
246 /* 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
247 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
248 unsigned int oldMask, newMask;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
249
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
250 oldMask = oldMods & bit;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
251 newMask = newMods & bit;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
252
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
253 if (oldMask && oldMask != newMask) { /* modifier up event */
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
254 /* 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
255 if (bit == NSAlphaShiftKeyMask) {
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
256 SDL_SendKeyboardKey(keyboard, SDL_PRESSED, (Uint8)scancode, mapping[i]);
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 SDL_SendKeyboardKey(keyboard, SDL_RELEASED, (Uint8)scancode, mapping[i]);
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
259 } else if (newMask && oldMask != newMask) { /* modifier down event */
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
260 SDL_SendKeyboardKey(keyboard, SDL_PRESSED, (Uint8)scancode, mapping[i]);
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
261 /* 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
262 if (bit == NSAlphaShiftKeyMask) {
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 }
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
265 }
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
266 }
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
267 }
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
268
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
269 /* This is a helper function for HandleModifierSide. This
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
270 * function reverts back to behavior before the distinction between
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
271 * sides was made.
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 static void
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
274 HandleNonDeviceModifier(int keyboard, unsigned short scancode,
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
275 unsigned int device_independent_mask,
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
276 unsigned int oldMods,
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
277 unsigned int newMods,
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
278 SDLKey key_sym)
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
279 {
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
280 unsigned int oldMask, newMask;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
281
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
282 /* 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
283 * figure out what changed
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 oldMask = oldMods & device_independent_mask;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
286 newMask = newMods & device_independent_mask;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
287
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
288 if (oldMask && oldMask != newMask) {
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
289 SDL_SendKeyboardKey(keyboard, SDL_RELEASED, (Uint8)scancode, key_sym);
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
290 } else if (newMask && oldMask != newMask) {
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
291 SDL_SendKeyboardKey(keyboard, SDL_PRESSED, (Uint8)scancode, key_sym);
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 }
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
294
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
295 /* This is a helper function for HandleModifierSide.
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
296 * This function sets the actual SDL_PrivateKeyboard event.
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 static void
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
299 HandleModifierOneSide(int keyboard, unsigned short scancode,
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
300 unsigned int oldMods, unsigned int newMods,
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
301 SDLKey key_sym,
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
302 unsigned int sided_device_dependent_mask)
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
303 {
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
304 unsigned int old_dep_mask, new_dep_mask;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
305
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
306 /* 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
307 * figure out what changed
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 old_dep_mask = oldMods & sided_device_dependent_mask;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
310 new_dep_mask = newMods & sided_device_dependent_mask;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
311
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
312 /* 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
313 * 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
314 * find out which it is.
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
315 */
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
316 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
317 SDL_SendKeyboardKey(keyboard, SDL_PRESSED, (Uint8)scancode, key_sym);
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
318 } else {
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
319 SDL_SendKeyboardKey(keyboard, SDL_RELEASED, (Uint8)scancode, key_sym);
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 }
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
322
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
323 /* This is a helper function for DoSidedModifiers.
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
324 * 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
325 * e.g. left-shift vs right-shift.
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 static void
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
328 HandleModifierSide(int keyboard, unsigned short scancode,
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
329 int device_independent_mask,
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
330 unsigned int oldMods, unsigned int newMods,
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
331 SDLKey left_key_sym,
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
332 SDLKey right_key_sym,
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
333 unsigned int left_device_dependent_mask,
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
334 unsigned int right_device_dependent_mask)
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
335 {
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
336 unsigned int device_dependent_mask = (left_device_dependent_mask |
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
337 right_device_dependent_mask);
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
338 unsigned int diff_mod;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
339
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
340 /* 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
341 * 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
342 * keyboard and revert to the unsided behavior.
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
343 */
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
344 if ((device_dependent_mask & newMods) == 0) {
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
345 /* Revert to the old behavior */
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
346 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
347 return;
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
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
350 /* 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
351 diff_mod = (device_dependent_mask & oldMods) ^
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
352 (device_dependent_mask & newMods);
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
353 if (diff_mod) {
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
354 /* 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
355 * 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
356 * change or if the bits don't both exist.
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
357 */
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
358 if (left_device_dependent_mask & diff_mod) {
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
359 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
360 }
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
361 if (right_device_dependent_mask & diff_mod) {
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
362 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
363 }
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
364 }
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
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
367 /* This is a helper function for DoSidedModifiers.
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
368 * 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
369 * 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
370 * can't still be down).
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 static void
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
373 ReleaseModifierSide(int keyboard, unsigned short scancode,
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
374 unsigned int device_independent_mask,
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
375 unsigned int oldMods, unsigned int newMods,
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
376 SDLKey left_key_sym,
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
377 SDLKey right_key_sym,
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
378 unsigned int left_device_dependent_mask,
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
379 unsigned int right_device_dependent_mask)
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
380 {
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
381 unsigned int device_dependent_mask = (left_device_dependent_mask |
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
382 right_device_dependent_mask);
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
383
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
384 /* 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
385 * 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
386 * keyboard and revert to the unsided behavior.
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
387 */
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
388 if ((device_dependent_mask & oldMods) == 0) {
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
389 /* 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
390 * to represent both, and release it.
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
391 */
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
392 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
393 return;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
394 }
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
395
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 * 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
398 * 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
399 * 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
400 * so I hope this doesn't cause other problems.
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 if ( left_device_dependent_mask & oldMods ) {
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
403 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
404 }
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
405 if ( right_device_dependent_mask & oldMods ) {
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
406 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
407 }
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
408 }
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 /* This is a helper function for DoSidedModifiers.
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
411 * This function handles the CapsLock case.
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 static void
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
414 HandleCapsLock(int keyboard, unsigned short scancode,
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
415 unsigned int oldMods, unsigned int newMods)
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
416 {
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
417 unsigned int oldMask, newMask;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
418
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
419 oldMask = oldMods & NSAlphaShiftKeyMask;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
420 newMask = newMods & NSAlphaShiftKeyMask;
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 if (oldMask != newMask) {
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
423 SDL_SendKeyboardKey(keyboard, SDL_PRESSED, (Uint8)scancode, SDLK_CAPSLOCK);
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
424 SDL_SendKeyboardKey(keyboard, SDL_RELEASED, (Uint8)scancode, SDLK_CAPSLOCK);
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
425 }
1960
118daa3a24cc Added numlock support
Sam Lantinga <slouken@libsdl.org>
parents: 1959
diff changeset
426
118daa3a24cc Added numlock support
Sam Lantinga <slouken@libsdl.org>
parents: 1959
diff changeset
427 oldMask = oldMods & NSNumericPadKeyMask;
118daa3a24cc Added numlock support
Sam Lantinga <slouken@libsdl.org>
parents: 1959
diff changeset
428 newMask = newMods & NSNumericPadKeyMask;
118daa3a24cc Added numlock support
Sam Lantinga <slouken@libsdl.org>
parents: 1959
diff changeset
429
118daa3a24cc Added numlock support
Sam Lantinga <slouken@libsdl.org>
parents: 1959
diff changeset
430 if (oldMask != newMask) {
118daa3a24cc Added numlock support
Sam Lantinga <slouken@libsdl.org>
parents: 1959
diff changeset
431 SDL_SendKeyboardKey(keyboard, SDL_PRESSED, (Uint8)scancode, SDLK_NUMLOCK);
118daa3a24cc Added numlock support
Sam Lantinga <slouken@libsdl.org>
parents: 1959
diff changeset
432 SDL_SendKeyboardKey(keyboard, SDL_RELEASED, (Uint8)scancode, SDLK_NUMLOCK);
118daa3a24cc Added numlock support
Sam Lantinga <slouken@libsdl.org>
parents: 1959
diff changeset
433 }
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
434 }
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
435
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
436 /* 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
437 * correct side of the key.
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
438 */
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
439 static void
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
440 DoSidedModifiers(int keyboard, unsigned short scancode,
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
441 unsigned int oldMods, unsigned int newMods)
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
442 {
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
443 /* 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
444 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
445 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
446 /* 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
447 * correspond to the _mapping arrays
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
448 */
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
449 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
450 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
451
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
452 unsigned int i, bit;
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 /* 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
455 HandleCapsLock(keyboard, scancode, oldMods, newMods);
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 /* 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
458 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
459 unsigned int oldMask, newMask;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
460
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
461 oldMask = oldMods & bit;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
462 newMask = newMods & bit;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
463
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
464 /* 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
465 * 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
466 */
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
467 if (newMask) {
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
468 HandleModifierSide(keyboard, scancode, bit, oldMods, newMods,
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
469 left_mapping[i], right_mapping[i],
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
470 left_device_mapping[i], right_device_mapping[i]);
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 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
473 * the device dependent bits to release the correct keys.
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
474 */
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
475 else if (oldMask && oldMask != newMask) {
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
476 ReleaseModifierSide(keyboard, scancode, bit, oldMods, newMods,
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
477 left_mapping[i], right_mapping[i],
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
478 left_device_mapping[i], right_device_mapping[i]);
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 }
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
481 }
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
482
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
483 static void
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
484 HandleModifiers(_THIS, unsigned short scancode, unsigned int modifierFlags)
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 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
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 if (modifierFlags == data->modifierFlags) {
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
489 return;
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
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 * 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
494 * left side and right side modifiers is available.
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 if (data->osversion >= 0x1030) {
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
497 DoSidedModifiers(data->keyboard, scancode, data->modifierFlags, modifierFlags);
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
498 } else {
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
499 DoUnsidedModifiers(data->keyboard, scancode, data->modifierFlags, modifierFlags);
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 data->modifierFlags = modifierFlags;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
502 }
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
503
1931
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
504 void
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
505 Cocoa_InitKeyboard(_THIS)
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
506 {
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
507 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
508 SDL_Keyboard keyboard;
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
509
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
510 InitKeymap(data->keymap);
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
511
1931
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
512 SDL_zero(keyboard);
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
513 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
514 }
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
515
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
516 void
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
517 Cocoa_HandleKeyEvent(_THIS, NSEvent *event)
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
518 {
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
519 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
520 unsigned short scancode = [event keyCode];
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
521 const char *text;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
522
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
523 if (scancode >= 256) {
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
524 /* 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
525 return;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
526 }
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
527
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
528 switch ([event type]) {
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
529 case NSKeyDown:
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
530 if ([event isARepeat]) {
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
531 break;
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 SDL_SendKeyboardKey(data->keyboard, SDL_PRESSED, (Uint8)scancode,
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
534 data->keymap[scancode]);
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
535 text = [[event characters] UTF8String];
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
536 if(text && *text) {
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
537 SDL_SendKeyboardText(data->keyboard, text);
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
538 }
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
539 break;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
540 case NSKeyUp:
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
541 SDL_SendKeyboardKey(data->keyboard, SDL_RELEASED, (Uint8)scancode,
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
542 data->keymap[scancode]);
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
543 break;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
544 case NSFlagsChanged:
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
545 HandleModifiers(_this, scancode, [event modifierFlags]);
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
546 break;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
547 }
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
548 }
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
549
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
550 void
1931
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
551 Cocoa_QuitKeyboard(_THIS)
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
552 {
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
553 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
554
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
555 SDL_DelKeyboard(data->keyboard);
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
556 }
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
557
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
558 /* vi: set ts=4 sw=4 expandtab: */