annotate src/video/cocoa/SDL_cocoakeyboard.m @ 3127:da6cbfa5b5f2 gsoc2009_IME

Get basic text input support working for Cocoa
author Jiang Jiang <gzjjgod@gmail.com>
date Mon, 25 May 2009 02:42:45 +0000
parents 99210400e8b9
children e42873b9c6f1
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
2859
99210400e8b9 Updated copyright date
Sam Lantinga <slouken@libsdl.org>
parents: 2305
diff changeset
3 Copyright (C) 1997-2009 Sam Lantinga
1931
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"
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
25
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
26 #include "../../events/SDL_keyboard_c.h"
2305
fbe8ff44c519 First pass of new SDL scancode concept for X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2304
diff changeset
27 #include "../../events/scancodes_darwin.h"
1931
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
28
2268
4baee598306d Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents: 2170
diff changeset
29 #include <Carbon/Carbon.h>
4baee598306d Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents: 2170
diff changeset
30
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
31
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
32 #ifndef NX_DEVICERCTLKEYMASK
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
33 #define NX_DEVICELCTLKEYMASK 0x00000001
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
34 #endif
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
35 #ifndef NX_DEVICELSHIFTKEYMASK
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
36 #define NX_DEVICELSHIFTKEYMASK 0x00000002
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
37 #endif
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
38 #ifndef NX_DEVICERSHIFTKEYMASK
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
39 #define NX_DEVICERSHIFTKEYMASK 0x00000004
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
40 #endif
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
41 #ifndef NX_DEVICELCMDKEYMASK
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
42 #define NX_DEVICELCMDKEYMASK 0x00000008
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
43 #endif
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
44 #ifndef NX_DEVICERCMDKEYMASK
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
45 #define NX_DEVICERCMDKEYMASK 0x00000010
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
46 #endif
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
47 #ifndef NX_DEVICELALTKEYMASK
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
48 #define NX_DEVICELALTKEYMASK 0x00000020
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
49 #endif
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
50 #ifndef NX_DEVICERALTKEYMASK
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
51 #define NX_DEVICERALTKEYMASK 0x00000040
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
52 #endif
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
53 #ifndef NX_DEVICERCTLKEYMASK
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
54 #define NX_DEVICERCTLKEYMASK 0x00002000
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
55 #endif
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
56
2289
f629d566ec6b Merged fix for bug #508 from SDL 1.2 revision 3495
Sam Lantinga <slouken@libsdl.org>
parents: 2273
diff changeset
57 @interface SDLTranslatorResponder : NSTextView
f629d566ec6b Merged fix for bug #508 from SDL 1.2 revision 3495
Sam Lantinga <slouken@libsdl.org>
parents: 2273
diff changeset
58 {
f629d566ec6b Merged fix for bug #508 from SDL 1.2 revision 3495
Sam Lantinga <slouken@libsdl.org>
parents: 2273
diff changeset
59 }
f629d566ec6b Merged fix for bug #508 from SDL 1.2 revision 3495
Sam Lantinga <slouken@libsdl.org>
parents: 2273
diff changeset
60 - (void) doCommandBySelector:(SEL)myselector;
f629d566ec6b Merged fix for bug #508 from SDL 1.2 revision 3495
Sam Lantinga <slouken@libsdl.org>
parents: 2273
diff changeset
61 @end
f629d566ec6b Merged fix for bug #508 from SDL 1.2 revision 3495
Sam Lantinga <slouken@libsdl.org>
parents: 2273
diff changeset
62
f629d566ec6b Merged fix for bug #508 from SDL 1.2 revision 3495
Sam Lantinga <slouken@libsdl.org>
parents: 2273
diff changeset
63 @implementation SDLTranslatorResponder
3127
da6cbfa5b5f2 Get basic text input support working for Cocoa
Jiang Jiang <gzjjgod@gmail.com>
parents: 2859
diff changeset
64
da6cbfa5b5f2 Get basic text input support working for Cocoa
Jiang Jiang <gzjjgod@gmail.com>
parents: 2859
diff changeset
65 - (void) insertText:(id) aString
da6cbfa5b5f2 Get basic text input support working for Cocoa
Jiang Jiang <gzjjgod@gmail.com>
parents: 2859
diff changeset
66 {
da6cbfa5b5f2 Get basic text input support working for Cocoa
Jiang Jiang <gzjjgod@gmail.com>
parents: 2859
diff changeset
67 const char *str;
da6cbfa5b5f2 Get basic text input support working for Cocoa
Jiang Jiang <gzjjgod@gmail.com>
parents: 2859
diff changeset
68
da6cbfa5b5f2 Get basic text input support working for Cocoa
Jiang Jiang <gzjjgod@gmail.com>
parents: 2859
diff changeset
69 NSLog(@"insertText: %@", aString);
da6cbfa5b5f2 Get basic text input support working for Cocoa
Jiang Jiang <gzjjgod@gmail.com>
parents: 2859
diff changeset
70
da6cbfa5b5f2 Get basic text input support working for Cocoa
Jiang Jiang <gzjjgod@gmail.com>
parents: 2859
diff changeset
71 if ([aString isKindOfClass: [NSAttributedString class]])
da6cbfa5b5f2 Get basic text input support working for Cocoa
Jiang Jiang <gzjjgod@gmail.com>
parents: 2859
diff changeset
72 str = [[aString string] UTF8String];
da6cbfa5b5f2 Get basic text input support working for Cocoa
Jiang Jiang <gzjjgod@gmail.com>
parents: 2859
diff changeset
73 else
da6cbfa5b5f2 Get basic text input support working for Cocoa
Jiang Jiang <gzjjgod@gmail.com>
parents: 2859
diff changeset
74 str = [aString UTF8String];
da6cbfa5b5f2 Get basic text input support working for Cocoa
Jiang Jiang <gzjjgod@gmail.com>
parents: 2859
diff changeset
75
da6cbfa5b5f2 Get basic text input support working for Cocoa
Jiang Jiang <gzjjgod@gmail.com>
parents: 2859
diff changeset
76 SDL_SendKeyboardText(0, str);
da6cbfa5b5f2 Get basic text input support working for Cocoa
Jiang Jiang <gzjjgod@gmail.com>
parents: 2859
diff changeset
77 }
da6cbfa5b5f2 Get basic text input support working for Cocoa
Jiang Jiang <gzjjgod@gmail.com>
parents: 2859
diff changeset
78
da6cbfa5b5f2 Get basic text input support working for Cocoa
Jiang Jiang <gzjjgod@gmail.com>
parents: 2859
diff changeset
79 - (void) doCommandBySelector:(SEL) myselector
da6cbfa5b5f2 Get basic text input support working for Cocoa
Jiang Jiang <gzjjgod@gmail.com>
parents: 2859
diff changeset
80 {
da6cbfa5b5f2 Get basic text input support working for Cocoa
Jiang Jiang <gzjjgod@gmail.com>
parents: 2859
diff changeset
81 NSLog(@"doCommandBySelector, passed down");
da6cbfa5b5f2 Get basic text input support working for Cocoa
Jiang Jiang <gzjjgod@gmail.com>
parents: 2859
diff changeset
82 [super doCommandBySelector: myselector];
da6cbfa5b5f2 Get basic text input support working for Cocoa
Jiang Jiang <gzjjgod@gmail.com>
parents: 2859
diff changeset
83 }
2289
f629d566ec6b Merged fix for bug #508 from SDL 1.2 revision 3495
Sam Lantinga <slouken@libsdl.org>
parents: 2273
diff changeset
84 @end
f629d566ec6b Merged fix for bug #508 from SDL 1.2 revision 3495
Sam Lantinga <slouken@libsdl.org>
parents: 2273
diff changeset
85
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
86 /* 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
87 * differentiating between left and right versions of the keys.
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
88 */
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
89 static void
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
90 DoUnsidedModifiers(int keyboard, unsigned short scancode,
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
91 unsigned int oldMods, unsigned int newMods)
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
92 {
2303
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
93 const int mapping[] = {
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
94 SDL_SCANCODE_CAPSLOCK,
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
95 SDL_SCANCODE_LSHIFT,
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
96 SDL_SCANCODE_LCTRL,
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
97 SDL_SCANCODE_LALT,
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
98 SDL_SCANCODE_LGUI
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
99 };
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
100 unsigned int i, bit;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
101
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
102 /* 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
103 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
104 unsigned int oldMask, newMask;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
105
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
106 oldMask = oldMods & bit;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
107 newMask = newMods & bit;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
108
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
109 if (oldMask && oldMask != newMask) { /* modifier up event */
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
110 /* 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
111 if (bit == NSAlphaShiftKeyMask) {
2303
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
112 SDL_SendKeyboardKey(keyboard, SDL_PRESSED, mapping[i]);
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
113 }
2303
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
114 SDL_SendKeyboardKey(keyboard, SDL_RELEASED, mapping[i]);
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
115 } else if (newMask && oldMask != newMask) { /* modifier down event */
2303
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
116 SDL_SendKeyboardKey(keyboard, SDL_PRESSED, mapping[i]);
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
117 /* 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
118 if (bit == NSAlphaShiftKeyMask) {
2303
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
119 SDL_SendKeyboardKey(keyboard, SDL_RELEASED, mapping[i]);
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
120 }
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
121 }
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
122 }
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
123 }
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
124
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
125 /* This is a helper function for HandleModifierSide. This
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
126 * function reverts back to behavior before the distinction between
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
127 * sides was made.
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
128 */
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
129 static void
2303
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
130 HandleNonDeviceModifier(int keyboard,
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
131 unsigned int device_independent_mask,
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
132 unsigned int oldMods,
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
133 unsigned int newMods,
2303
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
134 SDL_scancode scancode)
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
135 {
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
136 unsigned int oldMask, newMask;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
137
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
138 /* 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
139 * figure out what changed
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
140 */
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
141 oldMask = oldMods & device_independent_mask;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
142 newMask = newMods & device_independent_mask;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
143
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
144 if (oldMask && oldMask != newMask) {
2303
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
145 SDL_SendKeyboardKey(keyboard, SDL_RELEASED, scancode);
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
146 } else if (newMask && oldMask != newMask) {
2303
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
147 SDL_SendKeyboardKey(keyboard, SDL_PRESSED, scancode);
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
148 }
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
149 }
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
150
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
151 /* This is a helper function for HandleModifierSide.
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
152 * This function sets the actual SDL_PrivateKeyboard event.
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
153 */
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
154 static void
2303
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
155 HandleModifierOneSide(int keyboard,
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
156 unsigned int oldMods, unsigned int newMods,
2303
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
157 SDL_scancode scancode,
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
158 unsigned int sided_device_dependent_mask)
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
159 {
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
160 unsigned int old_dep_mask, new_dep_mask;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
161
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
162 /* 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
163 * figure out what changed
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
164 */
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
165 old_dep_mask = oldMods & sided_device_dependent_mask;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
166 new_dep_mask = newMods & sided_device_dependent_mask;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
167
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
168 /* 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
169 * 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
170 * find out which it is.
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
171 */
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
172 if (new_dep_mask && old_dep_mask != new_dep_mask) {
2303
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
173 SDL_SendKeyboardKey(keyboard, SDL_PRESSED, scancode);
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
174 } else {
2303
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
175 SDL_SendKeyboardKey(keyboard, SDL_RELEASED, scancode);
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
176 }
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 /* This is a helper function for DoSidedModifiers.
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
180 * 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
181 * e.g. left-shift vs right-shift.
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 static void
2303
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
184 HandleModifierSide(int keyboard,
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
185 int device_independent_mask,
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
186 unsigned int oldMods, unsigned int newMods,
2303
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
187 SDL_scancode left_scancode,
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
188 SDL_scancode right_scancode,
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
189 unsigned int left_device_dependent_mask,
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
190 unsigned int right_device_dependent_mask)
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
191 {
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
192 unsigned int device_dependent_mask = (left_device_dependent_mask |
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
193 right_device_dependent_mask);
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
194 unsigned int diff_mod;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
195
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
196 /* 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
197 * 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
198 * keyboard and revert to the unsided behavior.
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
199 */
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
200 if ((device_dependent_mask & newMods) == 0) {
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
201 /* Revert to the old behavior */
2303
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
202 HandleNonDeviceModifier(keyboard, device_independent_mask, oldMods, newMods, left_scancode);
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
203 return;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
204 }
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 /* 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
207 diff_mod = (device_dependent_mask & oldMods) ^
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
208 (device_dependent_mask & newMods);
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
209 if (diff_mod) {
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
210 /* 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
211 * 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
212 * change or if the bits don't both exist.
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 if (left_device_dependent_mask & diff_mod) {
2303
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
215 HandleModifierOneSide(keyboard, oldMods, newMods, left_scancode, left_device_dependent_mask);
1959
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 if (right_device_dependent_mask & diff_mod) {
2303
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
218 HandleModifierOneSide(keyboard, oldMods, newMods, right_scancode, right_device_dependent_mask);
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
219 }
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
220 }
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
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
223 /* This is a helper function for DoSidedModifiers.
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
224 * 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
225 * 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
226 * can't still be down).
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
227 */
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
228 static void
2303
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
229 ReleaseModifierSide(int keyboard,
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
230 unsigned int device_independent_mask,
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
231 unsigned int oldMods, unsigned int newMods,
2303
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
232 SDL_scancode left_scancode,
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
233 SDL_scancode right_scancode,
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
234 unsigned int left_device_dependent_mask,
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
235 unsigned int right_device_dependent_mask)
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
236 {
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
237 unsigned int device_dependent_mask = (left_device_dependent_mask |
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
238 right_device_dependent_mask);
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 /* 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
241 * 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
242 * keyboard and revert to the unsided behavior.
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 if ((device_dependent_mask & oldMods) == 0) {
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
245 /* 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
246 * to represent both, and release it.
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
247 */
2303
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
248 SDL_SendKeyboardKey(keyboard, SDL_RELEASED, left_scancode);
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
249 return;
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
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 * 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
254 * 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
255 * 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
256 * so I hope this doesn't cause other problems.
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 ( left_device_dependent_mask & oldMods ) {
2303
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
259 SDL_SendKeyboardKey(keyboard, SDL_RELEASED, left_scancode);
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
260 }
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
261 if ( right_device_dependent_mask & oldMods ) {
2303
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
262 SDL_SendKeyboardKey(keyboard, SDL_RELEASED, right_scancode);
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
263 }
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 /* This is a helper function for DoSidedModifiers.
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
267 * This function handles the CapsLock case.
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 static void
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
270 HandleCapsLock(int keyboard, unsigned short scancode,
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
271 unsigned int oldMods, unsigned int newMods)
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 unsigned int oldMask, newMask;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
274
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
275 oldMask = oldMods & NSAlphaShiftKeyMask;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
276 newMask = newMods & NSAlphaShiftKeyMask;
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 if (oldMask != newMask) {
2303
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
279 SDL_SendKeyboardKey(keyboard, SDL_PRESSED, SDL_SCANCODE_CAPSLOCK);
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
280 SDL_SendKeyboardKey(keyboard, SDL_RELEASED, SDL_SCANCODE_CAPSLOCK);
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
281 }
1960
118daa3a24cc Added numlock support
Sam Lantinga <slouken@libsdl.org>
parents: 1959
diff changeset
282
118daa3a24cc Added numlock support
Sam Lantinga <slouken@libsdl.org>
parents: 1959
diff changeset
283 oldMask = oldMods & NSNumericPadKeyMask;
118daa3a24cc Added numlock support
Sam Lantinga <slouken@libsdl.org>
parents: 1959
diff changeset
284 newMask = newMods & NSNumericPadKeyMask;
118daa3a24cc Added numlock support
Sam Lantinga <slouken@libsdl.org>
parents: 1959
diff changeset
285
118daa3a24cc Added numlock support
Sam Lantinga <slouken@libsdl.org>
parents: 1959
diff changeset
286 if (oldMask != newMask) {
2303
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
287 SDL_SendKeyboardKey(keyboard, SDL_PRESSED, SDL_SCANCODE_NUMLOCKCLEAR);
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
288 SDL_SendKeyboardKey(keyboard, SDL_RELEASED, SDL_SCANCODE_NUMLOCKCLEAR);
1960
118daa3a24cc Added numlock support
Sam Lantinga <slouken@libsdl.org>
parents: 1959
diff changeset
289 }
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
290 }
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
291
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
292 /* 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
293 * correct side of the key.
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 static void
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
296 DoSidedModifiers(int keyboard, unsigned short scancode,
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
297 unsigned int oldMods, unsigned int newMods)
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 /* Set up arrays for the key syms for the left and right side. */
2303
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
300 const SDL_scancode left_mapping[] = {
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
301 SDL_SCANCODE_LSHIFT,
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
302 SDL_SCANCODE_LCTRL,
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
303 SDL_SCANCODE_LALT,
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
304 SDL_SCANCODE_LGUI
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
305 };
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
306 const SDL_scancode right_mapping[] = {
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
307 SDL_SCANCODE_RSHIFT,
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
308 SDL_SCANCODE_RCTRL,
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
309 SDL_SCANCODE_RALT,
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
310 SDL_SCANCODE_RGUI
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
311 };
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
312 /* 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
313 * correspond to the _mapping arrays
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
314 */
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
315 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
316 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
317
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
318 unsigned int i, bit;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
319
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
320 /* 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
321 HandleCapsLock(keyboard, scancode, oldMods, newMods);
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 /* 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
324 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
325 unsigned int oldMask, newMask;
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 oldMask = oldMods & bit;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
328 newMask = newMods & bit;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
329
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
330 /* 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
331 * 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
332 */
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
333 if (newMask) {
2303
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
334 HandleModifierSide(keyboard, bit, oldMods, newMods,
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
335 left_mapping[i], right_mapping[i],
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
336 left_device_mapping[i], right_device_mapping[i]);
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
337 }
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
338 /* 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
339 * the device dependent bits to release the correct keys.
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 else if (oldMask && oldMask != newMask) {
2303
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
342 ReleaseModifierSide(keyboard, bit, oldMods, newMods,
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
343 left_mapping[i], right_mapping[i],
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
344 left_device_mapping[i], right_device_mapping[i]);
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
345 }
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
346 }
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
347 }
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 static void
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
350 HandleModifiers(_THIS, unsigned short scancode, unsigned int modifierFlags)
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
351 {
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
352 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
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 if (modifierFlags == data->modifierFlags) {
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
355 return;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
356 }
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 /*
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
359 * 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
360 * left side and right side modifiers is available.
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
361 */
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
362 if (data->osversion >= 0x1030) {
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
363 DoSidedModifiers(data->keyboard, scancode, data->modifierFlags, modifierFlags);
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
364 } else {
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
365 DoUnsidedModifiers(data->keyboard, scancode, data->modifierFlags, modifierFlags);
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 data->modifierFlags = modifierFlags;
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
2303
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
370 static void
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
371 UpdateKeymap(SDL_VideoData *data)
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
372 {
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
373 KeyboardLayoutRef key_layout;
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
374 const void *chr_data;
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
375 int i;
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
376 SDL_scancode scancode;
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
377 SDLKey keymap[SDL_NUM_SCANCODES];
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
378
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
379 /* See if the keymap needs to be updated */
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
380 KLGetCurrentKeyboardLayout(&key_layout);
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
381 if (key_layout == data->key_layout) {
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
382 return;
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
383 }
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
384 data->key_layout = key_layout;
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
385
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
386 SDL_GetDefaultKeymap(keymap);
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
387
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
388 /* Try Unicode data first (preferred as of Mac OS X 10.5) */
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
389 KLGetKeyboardLayoutProperty(key_layout, kKLuchrData, &chr_data);
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
390 if (chr_data) {
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
391 UInt32 keyboard_type = LMGetKbdType();
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
392 OSStatus err;
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
393
2305
fbe8ff44c519 First pass of new SDL scancode concept for X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2304
diff changeset
394 for (i = 0; i < SDL_arraysize(darwin_scancode_table); i++) {
2303
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
395 UniChar s[8];
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
396 UniCharCount len;
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
397 UInt32 dead_key_state;
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
398
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
399 /* Make sure this scancode is a valid character scancode */
2305
fbe8ff44c519 First pass of new SDL scancode concept for X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2304
diff changeset
400 scancode = darwin_scancode_table[i];
2303
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
401 if (scancode == SDL_SCANCODE_UNKNOWN ||
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
402 (keymap[scancode] & SDLK_SCANCODE_MASK)) {
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
403 continue;
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
404 }
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
405
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
406 dead_key_state = 0;
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
407 err = UCKeyTranslate (chr_data, i, kUCKeyActionDown,
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
408 0, keyboard_type,
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
409 kUCKeyTranslateNoDeadKeysMask,
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
410 &dead_key_state, 8, &len, s);
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
411 if (err != noErr)
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
412 continue;
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
413
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
414 if (len > 0 && s[0] != 0x10) {
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
415 keymap[scancode] = s[0];
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
416 }
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
417 }
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
418 SDL_SetKeymap(data->keyboard, 0, keymap, SDL_NUM_SCANCODES);
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
419 return;
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
420 }
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
421
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
422 /* Fall back to older style key map data */
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
423 KLGetKeyboardLayoutProperty(key_layout, kKLKCHRData, &chr_data);
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
424 if (chr_data) {
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
425 for (i = 0; i < 128; i++) {
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
426 UInt32 c, state = 0;
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
427
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
428 /* Make sure this scancode is a valid character scancode */
2305
fbe8ff44c519 First pass of new SDL scancode concept for X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2304
diff changeset
429 scancode = darwin_scancode_table[i];
2303
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
430 if (scancode == SDL_SCANCODE_UNKNOWN ||
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
431 (keymap[scancode] & SDLK_SCANCODE_MASK)) {
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
432 continue;
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
433 }
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
434
2304
50f58ce12497 Christian's comment:
Sam Lantinga <slouken@libsdl.org>
parents: 2303
diff changeset
435 c = KeyTranslate (chr_data, i, &state) & 255;
2303
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
436 if (state) {
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
437 /* Dead key, process key up */
2304
50f58ce12497 Christian's comment:
Sam Lantinga <slouken@libsdl.org>
parents: 2303
diff changeset
438 c = KeyTranslate (chr_data, i | 128, &state) & 255;
2303
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
439 }
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
440
2304
50f58ce12497 Christian's comment:
Sam Lantinga <slouken@libsdl.org>
parents: 2303
diff changeset
441 if (c != 0 && c != 0x10) {
2303
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
442 /* MacRoman to Unicode table, taken from X.org sources */
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
443 static const unsigned short macroman_table[128] = {
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
444 0xc4, 0xc5, 0xc7, 0xc9, 0xd1, 0xd6, 0xdc, 0xe1,
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
445 0xe0, 0xe2, 0xe4, 0xe3, 0xe5, 0xe7, 0xe9, 0xe8,
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
446 0xea, 0xeb, 0xed, 0xec, 0xee, 0xef, 0xf1, 0xf3,
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
447 0xf2, 0xf4, 0xf6, 0xf5, 0xfa, 0xf9, 0xfb, 0xfc,
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
448 0x2020, 0xb0, 0xa2, 0xa3, 0xa7, 0x2022, 0xb6, 0xdf,
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
449 0xae, 0xa9, 0x2122, 0xb4, 0xa8, 0x2260, 0xc6, 0xd8,
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
450 0x221e, 0xb1, 0x2264, 0x2265, 0xa5, 0xb5, 0x2202, 0x2211,
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
451 0x220f, 0x3c0, 0x222b, 0xaa, 0xba, 0x3a9, 0xe6, 0xf8,
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
452 0xbf, 0xa1, 0xac, 0x221a, 0x192, 0x2248, 0x2206, 0xab,
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
453 0xbb, 0x2026, 0xa0, 0xc0, 0xc3, 0xd5, 0x152, 0x153,
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
454 0x2013, 0x2014, 0x201c, 0x201d, 0x2018, 0x2019, 0xf7, 0x25ca,
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
455 0xff, 0x178, 0x2044, 0x20ac, 0x2039, 0x203a, 0xfb01, 0xfb02,
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
456 0x2021, 0xb7, 0x201a, 0x201e, 0x2030, 0xc2, 0xca, 0xc1,
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
457 0xcb, 0xc8, 0xcd, 0xce, 0xcf, 0xcc, 0xd3, 0xd4,
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
458 0xf8ff, 0xd2, 0xda, 0xdb, 0xd9, 0x131, 0x2c6, 0x2dc,
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
459 0xaf, 0x2d8, 0x2d9, 0x2da, 0xb8, 0x2dd, 0x2db, 0x2c7,
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
460 };
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
461
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
462 if (c >= 128) {
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
463 c = macroman_table[c - 128];
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
464 }
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
465 keymap[scancode] = c;
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
466 }
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
467 }
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
468 SDL_SetKeymap(data->keyboard, 0, keymap, SDL_NUM_SCANCODES);
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
469 return;
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
470 }
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
471 }
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
472
1931
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
473 void
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
474 Cocoa_InitKeyboard(_THIS)
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
475 {
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
476 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
477 SDL_Keyboard keyboard;
2170
243bc7ae5a21 Needed an autorelease pool around the NSText allocation
Sam Lantinga <slouken@libsdl.org>
parents: 2169
diff changeset
478 NSAutoreleasePool *pool;
1931
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
479
2170
243bc7ae5a21 Needed an autorelease pool around the NSText allocation
Sam Lantinga <slouken@libsdl.org>
parents: 2169
diff changeset
480 pool = [[NSAutoreleasePool alloc] init];
2289
f629d566ec6b Merged fix for bug #508 from SDL 1.2 revision 3495
Sam Lantinga <slouken@libsdl.org>
parents: 2273
diff changeset
481 data->fieldEdit = [[SDLTranslatorResponder 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
482 [pool release];
2169
13cf2d5eda86 Added key composition support, courtesy of Kuon
Sam Lantinga <slouken@libsdl.org>
parents: 2129
diff changeset
483
1931
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
484 SDL_zero(keyboard);
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
485 data->keyboard = SDL_AddKeyboard(&keyboard, -1);
2303
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
486 UpdateKeymap(data);
2268
4baee598306d Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents: 2170
diff changeset
487
4baee598306d Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents: 2170
diff changeset
488 /* Set our own names for the platform-dependent but layout-independent keys */
2303
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
489 /* This key is NumLock on the MacBook keyboard. :) */
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
490 /*SDL_SetScancodeName(SDL_SCANCODE_NUMLOCKCLEAR, "Clear");*/
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
491 SDL_SetScancodeName(SDL_SCANCODE_LALT, "Left Option");
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
492 SDL_SetScancodeName(SDL_SCANCODE_LGUI, "Left Command");
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
493 SDL_SetScancodeName(SDL_SCANCODE_RALT, "Right Option");
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
494 SDL_SetScancodeName(SDL_SCANCODE_RGUI, "Right Command");
1931
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
495 }
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
496
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
497 void
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
498 Cocoa_HandleKeyEvent(_THIS, NSEvent *event)
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
499 {
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
500 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
501 unsigned short scancode = [event keyCode];
2303
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
502 SDL_scancode code;
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
503 const char *text;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
504
2268
4baee598306d Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents: 2170
diff changeset
505 if ((scancode == 10 || scancode == 50) && KBGetLayoutType(LMGetKbdType()) == kKeyboardISO) {
4baee598306d Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents: 2170
diff changeset
506 /* see comments in SDL_cocoakeys.h */
4baee598306d Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents: 2170
diff changeset
507 scancode = 60 - scancode;
4baee598306d Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents: 2170
diff changeset
508 }
2305
fbe8ff44c519 First pass of new SDL scancode concept for X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2304
diff changeset
509 if (scancode < SDL_arraysize(darwin_scancode_table)) {
fbe8ff44c519 First pass of new SDL scancode concept for X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2304
diff changeset
510 code = darwin_scancode_table[scancode];
2268
4baee598306d Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents: 2170
diff changeset
511 }
4baee598306d Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents: 2170
diff changeset
512 else {
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
513 /* Hmm, does this ever happen? If so, need to extend the keymap... */
2303
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
514 code = SDL_SCANCODE_UNKNOWN;
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
515 }
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
516
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
517 switch ([event type]) {
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
518 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
519 if (![event isARepeat]) {
2303
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
520 /* See if we need to rebuild the keyboard layout */
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
521 UpdateKeymap(data);
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
522
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
523 SDL_SendKeyboardKey(data->keyboard, SDL_PRESSED, code);
2268
4baee598306d Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents: 2170
diff changeset
524 #if 1
2303
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
525 if (code == SDL_SCANCODE_UNKNOWN) {
2268
4baee598306d Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents: 2170
diff changeset
526 fprintf(stderr, "The key you just pressed is not recognized by SDL. To help get this fixed, report this to the SDL mailing list <sdl@libsdl.org> or to Christian Walther <cwalther@gmx.ch>. Mac virtual key code is %d.\n", scancode);
4baee598306d Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents: 2170
diff changeset
527 }
4baee598306d Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents: 2170
diff changeset
528 #endif
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
529 }
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
530 if (SDL_EventState(SDL_TEXTINPUT, SDL_QUERY)) {
2268
4baee598306d Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents: 2170
diff changeset
531 /* FIXME CW 2007-08-16: only send those events to the field editor for which we actually want text events, not e.g. esc or function keys. Arrow keys in particular seem to produce crashes sometimes. */
3127
da6cbfa5b5f2 Get basic text input support working for Cocoa
Jiang Jiang <gzjjgod@gmail.com>
parents: 2859
diff changeset
532 NSLog(@"interpretKeyEvents");
da6cbfa5b5f2 Get basic text input support working for Cocoa
Jiang Jiang <gzjjgod@gmail.com>
parents: 2859
diff changeset
533 if (! [[data->fieldEdit superview] isEqual: [[event window] contentView]])
da6cbfa5b5f2 Get basic text input support working for Cocoa
Jiang Jiang <gzjjgod@gmail.com>
parents: 2859
diff changeset
534 {
da6cbfa5b5f2 Get basic text input support working for Cocoa
Jiang Jiang <gzjjgod@gmail.com>
parents: 2859
diff changeset
535 NSLog(@"add fieldEdit to window contentView");
da6cbfa5b5f2 Get basic text input support working for Cocoa
Jiang Jiang <gzjjgod@gmail.com>
parents: 2859
diff changeset
536 [data->fieldEdit removeFromSuperview];
da6cbfa5b5f2 Get basic text input support working for Cocoa
Jiang Jiang <gzjjgod@gmail.com>
parents: 2859
diff changeset
537 [[[event window] contentView] addSubview: data->fieldEdit];
da6cbfa5b5f2 Get basic text input support working for Cocoa
Jiang Jiang <gzjjgod@gmail.com>
parents: 2859
diff changeset
538 [[event window] makeFirstResponder: data->fieldEdit];
da6cbfa5b5f2 Get basic text input support working for Cocoa
Jiang Jiang <gzjjgod@gmail.com>
parents: 2859
diff changeset
539 }
2169
13cf2d5eda86 Added key composition support, courtesy of Kuon
Sam Lantinga <slouken@libsdl.org>
parents: 2129
diff changeset
540 [data->fieldEdit interpretKeyEvents:[NSArray arrayWithObject:event]];
3127
da6cbfa5b5f2 Get basic text input support working for Cocoa
Jiang Jiang <gzjjgod@gmail.com>
parents: 2859
diff changeset
541 #if 0
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
542 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
543 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
544 SDL_SendKeyboardText(data->keyboard, text);
2273
a25bc0f79557 Fixed bug #471
Sam Lantinga <slouken@libsdl.org>
parents: 2270
diff changeset
545 [data->fieldEdit setString:@""];
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 }
3127
da6cbfa5b5f2 Get basic text input support working for Cocoa
Jiang Jiang <gzjjgod@gmail.com>
parents: 2859
diff changeset
547 #endif
1959
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 break;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
550 case NSKeyUp:
2303
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
551 SDL_SendKeyboardKey(data->keyboard, SDL_RELEASED, code);
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
552 break;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
553 case NSFlagsChanged:
2268
4baee598306d Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents: 2170
diff changeset
554 /* FIXME CW 2007-08-14: check if this whole mess that takes up half of this file is really necessary */
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
555 HandleModifiers(_this, scancode, [event modifierFlags]);
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
556 break;
2268
4baee598306d Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents: 2170
diff changeset
557 default: /* just to avoid compiler warnings */
4baee598306d Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents: 2170
diff changeset
558 break;
4baee598306d Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents: 2170
diff changeset
559 }
4baee598306d Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents: 2170
diff changeset
560 }
4baee598306d Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents: 2170
diff changeset
561
1959
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;
2270
d5a11262f067 Date: Sun, 19 Aug 2007 18:29:28 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 2268
diff changeset
566 NSAutoreleasePool *pool;
1931
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
567
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
568 SDL_DelKeyboard(data->keyboard);
2169
13cf2d5eda86 Added key composition support, courtesy of Kuon
Sam Lantinga <slouken@libsdl.org>
parents: 2129
diff changeset
569
2270
d5a11262f067 Date: Sun, 19 Aug 2007 18:29:28 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 2268
diff changeset
570 pool = [[NSAutoreleasePool alloc] init];
2169
13cf2d5eda86 Added key composition support, courtesy of Kuon
Sam Lantinga <slouken@libsdl.org>
parents: 2129
diff changeset
571 [data->fieldEdit release];
2270
d5a11262f067 Date: Sun, 19 Aug 2007 18:29:28 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 2268
diff changeset
572 [pool release];
1931
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
573 }
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
574
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
575 /* vi: set ts=4 sw=4 expandtab: */