Mercurial > sdl-ios-xcode
annotate src/video/cocoa/SDL_cocoakeyboard.m @ 2289:f629d566ec6b
Merged fix for bug #508 from SDL 1.2 revision 3495
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sat, 29 Dec 2007 21:36:17 +0000 |
parents | a25bc0f79557 |
children | d87417504c75 |
rev | line source |
---|---|
1931
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1 /* |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
2 SDL - Simple DirectMedia Layer |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
3 Copyright (C) 1997-2006 Sam Lantinga |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
4 |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
5 This library is free software; you can redistribute it and/or |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
6 modify it under the terms of the GNU Lesser General Public |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
7 License as published by the Free Software Foundation; either |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
8 version 2.1 of the License, or (at your option) any later version. |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
9 |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
10 This library is distributed in the hope that it will be useful, |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
11 but WITHOUT ANY WARRANTY; without even the implied warranty of |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
13 Lesser General Public License for more details. |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
14 |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
15 You should have received a copy of the GNU Lesser General Public |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
16 License along with this library; if not, write to the Free Software |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
18 |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
19 Sam Lantinga |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
20 slouken@libsdl.org |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
21 */ |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
22 #include "SDL_config.h" |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
23 |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
24 #include "SDL_cocoavideo.h" |
1959
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
25 #include "SDL_cocoakeys.h" |
1931
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
26 |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
27 #include "../../events/SDL_keyboard_c.h" |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
28 |
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 |
f629d566ec6b
Merged fix for bug #508 from SDL 1.2 revision 3495
Sam Lantinga <slouken@libsdl.org>
parents:
2273
diff
changeset
|
64 - (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
|
65 @end |
f629d566ec6b
Merged fix for bug #508 from SDL 1.2 revision 3495
Sam Lantinga <slouken@libsdl.org>
parents:
2273
diff
changeset
|
66 |
1959
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
67 /* 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
|
68 * differentiating between left and right versions of the keys. |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
69 */ |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
70 static void |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
71 DoUnsidedModifiers(int keyboard, unsigned short scancode, |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
72 unsigned int oldMods, unsigned int newMods) |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
73 { |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
74 const int mapping[] = { SDLK_CAPSLOCK, SDLK_LSHIFT, SDLK_LCTRL, SDLK_LALT, SDLK_LMETA }; |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
75 unsigned int i, bit; |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
76 |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
77 /* 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
|
78 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
|
79 unsigned int oldMask, newMask; |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
80 |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
81 oldMask = oldMods & bit; |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
82 newMask = newMods & bit; |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
83 |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
84 if (oldMask && oldMask != newMask) { /* modifier up event */ |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
85 /* 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
|
86 if (bit == NSAlphaShiftKeyMask) { |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
87 SDL_SendKeyboardKey(keyboard, SDL_PRESSED, (Uint8)scancode, mapping[i]); |
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 SDL_SendKeyboardKey(keyboard, SDL_RELEASED, (Uint8)scancode, mapping[i]); |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
90 } else if (newMask && oldMask != newMask) { /* modifier down event */ |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
91 SDL_SendKeyboardKey(keyboard, SDL_PRESSED, (Uint8)scancode, mapping[i]); |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
92 /* 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
|
93 if (bit == NSAlphaShiftKeyMask) { |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
94 SDL_SendKeyboardKey(keyboard, SDL_RELEASED, (Uint8)scancode, mapping[i]); |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
95 } |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
96 } |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
97 } |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
98 } |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
99 |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
100 /* This is a helper function for HandleModifierSide. This |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
101 * function reverts back to behavior before the distinction between |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
102 * sides was made. |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
103 */ |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
104 static void |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
105 HandleNonDeviceModifier(int keyboard, unsigned short scancode, |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
106 unsigned int device_independent_mask, |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
107 unsigned int oldMods, |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
108 unsigned int newMods, |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
109 SDLKey key_sym) |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
110 { |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
111 unsigned int oldMask, newMask; |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
112 |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
113 /* 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
|
114 * figure out what changed |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
115 */ |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
116 oldMask = oldMods & device_independent_mask; |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
117 newMask = newMods & device_independent_mask; |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
118 |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
119 if (oldMask && oldMask != newMask) { |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
120 SDL_SendKeyboardKey(keyboard, SDL_RELEASED, (Uint8)scancode, key_sym); |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
121 } else if (newMask && oldMask != newMask) { |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
122 SDL_SendKeyboardKey(keyboard, SDL_PRESSED, (Uint8)scancode, key_sym); |
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 |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
126 /* This is a helper function for HandleModifierSide. |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
127 * This function sets the actual SDL_PrivateKeyboard event. |
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 |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
130 HandleModifierOneSide(int keyboard, unsigned short scancode, |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
131 unsigned int oldMods, unsigned int newMods, |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
132 SDLKey key_sym, |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
133 unsigned int sided_device_dependent_mask) |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
134 { |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
135 unsigned int old_dep_mask, new_dep_mask; |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
136 |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
137 /* 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
|
138 * figure out what changed |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
139 */ |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
140 old_dep_mask = oldMods & sided_device_dependent_mask; |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
141 new_dep_mask = newMods & sided_device_dependent_mask; |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
142 |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
143 /* 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
|
144 * 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
|
145 * find out which it is. |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
146 */ |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
147 if (new_dep_mask && old_dep_mask != new_dep_mask) { |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
148 SDL_SendKeyboardKey(keyboard, SDL_PRESSED, (Uint8)scancode, key_sym); |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
149 } else { |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
150 SDL_SendKeyboardKey(keyboard, SDL_RELEASED, (Uint8)scancode, key_sym); |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
151 } |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
152 } |
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 /* This is a helper function for DoSidedModifiers. |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
155 * 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
|
156 * e.g. left-shift vs right-shift. |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
157 */ |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
158 static void |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
159 HandleModifierSide(int keyboard, unsigned short scancode, |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
160 int device_independent_mask, |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
161 unsigned int oldMods, unsigned int newMods, |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
162 SDLKey left_key_sym, |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
163 SDLKey right_key_sym, |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
164 unsigned int left_device_dependent_mask, |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
165 unsigned int right_device_dependent_mask) |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
166 { |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
167 unsigned int device_dependent_mask = (left_device_dependent_mask | |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
168 right_device_dependent_mask); |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
169 unsigned int diff_mod; |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
170 |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
171 /* 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
|
172 * 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
|
173 * keyboard and revert to the unsided behavior. |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
174 */ |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
175 if ((device_dependent_mask & newMods) == 0) { |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
176 /* Revert to the old behavior */ |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
177 HandleNonDeviceModifier(keyboard, scancode, device_independent_mask, oldMods, newMods, left_key_sym); |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
178 return; |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
179 } |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
180 |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
181 /* 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
|
182 diff_mod = (device_dependent_mask & oldMods) ^ |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
183 (device_dependent_mask & newMods); |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
184 if (diff_mod) { |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
185 /* 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
|
186 * 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
|
187 * change or if the bits don't both exist. |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
188 */ |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
189 if (left_device_dependent_mask & diff_mod) { |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
190 HandleModifierOneSide(keyboard, scancode, oldMods, newMods, left_key_sym, left_device_dependent_mask); |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
191 } |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
192 if (right_device_dependent_mask & diff_mod) { |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
193 HandleModifierOneSide(keyboard, scancode, oldMods, newMods, right_key_sym, right_device_dependent_mask); |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
194 } |
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 } |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
197 |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
198 /* This is a helper function for DoSidedModifiers. |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
199 * 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
|
200 * 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
|
201 * can't still be down). |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
202 */ |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
203 static void |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
204 ReleaseModifierSide(int keyboard, unsigned short scancode, |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
205 unsigned int device_independent_mask, |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
206 unsigned int oldMods, unsigned int newMods, |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
207 SDLKey left_key_sym, |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
208 SDLKey right_key_sym, |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
209 unsigned int left_device_dependent_mask, |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
210 unsigned int right_device_dependent_mask) |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
211 { |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
212 unsigned int device_dependent_mask = (left_device_dependent_mask | |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
213 right_device_dependent_mask); |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
214 |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
215 /* 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
|
216 * 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
|
217 * keyboard and revert to the unsided behavior. |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
218 */ |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
219 if ((device_dependent_mask & oldMods) == 0) { |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
220 /* 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
|
221 * to represent both, and release it. |
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 SDL_SendKeyboardKey(keyboard, SDL_RELEASED, (Uint8)scancode, left_key_sym); |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
224 return; |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
225 } |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
226 |
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 * 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
|
229 * 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
|
230 * 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
|
231 * so I hope this doesn't cause other problems. |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
232 */ |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
233 if ( left_device_dependent_mask & oldMods ) { |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
234 SDL_SendKeyboardKey(keyboard, SDL_RELEASED, (Uint8)scancode, left_key_sym); |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
235 } |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
236 if ( right_device_dependent_mask & oldMods ) { |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
237 SDL_SendKeyboardKey(keyboard, SDL_RELEASED, (Uint8)scancode, right_key_sym); |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
238 } |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
239 } |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
240 |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
241 /* This is a helper function for DoSidedModifiers. |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
242 * This function handles the CapsLock case. |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
243 */ |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
244 static void |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
245 HandleCapsLock(int keyboard, unsigned short scancode, |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
246 unsigned int oldMods, unsigned int newMods) |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
247 { |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
248 unsigned int oldMask, newMask; |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
249 |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
250 oldMask = oldMods & NSAlphaShiftKeyMask; |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
251 newMask = newMods & NSAlphaShiftKeyMask; |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
252 |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
253 if (oldMask != newMask) { |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
254 SDL_SendKeyboardKey(keyboard, SDL_PRESSED, (Uint8)scancode, SDLK_CAPSLOCK); |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
255 SDL_SendKeyboardKey(keyboard, SDL_RELEASED, (Uint8)scancode, SDLK_CAPSLOCK); |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
256 } |
1960 | 257 |
258 oldMask = oldMods & NSNumericPadKeyMask; | |
259 newMask = newMods & NSNumericPadKeyMask; | |
260 | |
261 if (oldMask != newMask) { | |
2268
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
262 SDL_SendKeyboardKey(keyboard, SDL_PRESSED, (Uint8)scancode, SDLK_KP_NUMLOCKCLEAR); |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
263 SDL_SendKeyboardKey(keyboard, SDL_RELEASED, (Uint8)scancode, SDLK_KP_NUMLOCKCLEAR); |
1960 | 264 } |
1959
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
265 } |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
266 |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
267 /* 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
|
268 * correct side of the key. |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
269 */ |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
270 static void |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
271 DoSidedModifiers(int keyboard, unsigned short scancode, |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
272 unsigned int oldMods, unsigned int newMods) |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
273 { |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
274 /* Set up arrays for the key syms for the left and right side. */ |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
275 const SDLKey left_mapping[] = { SDLK_LSHIFT, SDLK_LCTRL, SDLK_LALT, SDLK_LMETA }; |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
276 const SDLKey right_mapping[] = { SDLK_RSHIFT, SDLK_RCTRL, SDLK_RALT, SDLK_RMETA }; |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
277 /* 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
|
278 * correspond to the _mapping arrays |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
279 */ |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
280 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
|
281 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
|
282 |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
283 unsigned int i, bit; |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
284 |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
285 /* 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
|
286 HandleCapsLock(keyboard, scancode, oldMods, newMods); |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
287 |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
288 /* 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
|
289 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
|
290 unsigned int oldMask, newMask; |
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 oldMask = oldMods & bit; |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
293 newMask = newMods & bit; |
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 /* 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
|
296 * 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
|
297 */ |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
298 if (newMask) { |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
299 HandleModifierSide(keyboard, scancode, bit, oldMods, newMods, |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
300 left_mapping[i], right_mapping[i], |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
301 left_device_mapping[i], right_device_mapping[i]); |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
302 } |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
303 /* 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
|
304 * the device dependent bits to release the correct keys. |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
305 */ |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
306 else if (oldMask && oldMask != newMask) { |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
307 ReleaseModifierSide(keyboard, scancode, bit, oldMods, newMods, |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
308 left_mapping[i], right_mapping[i], |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
309 left_device_mapping[i], right_device_mapping[i]); |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
310 } |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
311 } |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
312 } |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
313 |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
314 static void |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
315 HandleModifiers(_THIS, unsigned short scancode, unsigned int modifierFlags) |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
316 { |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
317 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata; |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
318 |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
319 if (modifierFlags == data->modifierFlags) { |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
320 return; |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
321 } |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
322 |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
323 /* |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
324 * 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
|
325 * left side and right side modifiers is available. |
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 if (data->osversion >= 0x1030) { |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
328 DoSidedModifiers(data->keyboard, scancode, data->modifierFlags, modifierFlags); |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
329 } else { |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
330 DoUnsidedModifiers(data->keyboard, scancode, data->modifierFlags, modifierFlags); |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
331 } |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
332 data->modifierFlags = modifierFlags; |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
333 } |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
334 |
1931
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
335 void |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
336 Cocoa_InitKeyboard(_THIS) |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
337 { |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
338 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
|
339 SDL_Keyboard keyboard; |
2170
243bc7ae5a21
Needed an autorelease pool around the NSText allocation
Sam Lantinga <slouken@libsdl.org>
parents:
2169
diff
changeset
|
340 NSAutoreleasePool *pool; |
1931
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
341 |
2170
243bc7ae5a21
Needed an autorelease pool around the NSText allocation
Sam Lantinga <slouken@libsdl.org>
parents:
2169
diff
changeset
|
342 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
|
343 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
|
344 [pool release]; |
2169
13cf2d5eda86
Added key composition support, courtesy of Kuon
Sam Lantinga <slouken@libsdl.org>
parents:
2129
diff
changeset
|
345 |
1931
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
346 SDL_zero(keyboard); |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
347 data->keyboard = SDL_AddKeyboard(&keyboard, -1); |
2268
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
348 |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
349 /* Set our own names for the platform-dependent but layout-independent keys */ |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
350 SDL_SetKeyName(SDLK_KP_NUMLOCKCLEAR, "clear"); |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
351 SDL_SetKeyName(SDLK_LALT, "left option"); |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
352 SDL_SetKeyName(SDLK_LMETA, "left command"); |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
353 SDL_SetKeyName(SDLK_RALT, "right option"); |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
354 SDL_SetKeyName(SDLK_RMETA, "right command"); |
1931
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
355 } |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
356 |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
357 void |
1959
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
358 Cocoa_HandleKeyEvent(_THIS, NSEvent *event) |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
359 { |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
360 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata; |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
361 unsigned short scancode = [event keyCode]; |
2268
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
362 SDLKey physicalKey; |
1959
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
363 const char *text; |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
364 |
2268
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
365 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
|
366 /* 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
|
367 scancode = 60 - scancode; |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
368 } |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
369 if (scancode < SDL_arraysize(macToSDLKey)) { |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
370 physicalKey = macToSDLKey[scancode]; |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
371 } |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
372 else { |
1959
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
373 /* Hmm, does this ever happen? If so, need to extend the keymap... */ |
2268
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
374 physicalKey = SDLK_UNKNOWN; |
1959
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
375 } |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
376 |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
377 switch ([event type]) { |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
378 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
|
379 if (![event isARepeat]) { |
2268
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
380 SDL_SendKeyboardKey(data->keyboard, SDL_PRESSED, (Uint8)scancode, physicalKey); |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
381 #if 1 |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
382 if (physicalKey == SDLK_UNKNOWN) { |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
383 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
|
384 } |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
385 #endif |
1959
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
386 } |
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
|
387 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
|
388 /* 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. */ |
2169
13cf2d5eda86
Added key composition support, courtesy of Kuon
Sam Lantinga <slouken@libsdl.org>
parents:
2129
diff
changeset
|
389 [data->fieldEdit interpretKeyEvents:[NSArray arrayWithObject:event]]; |
2129
047245361002
Key repeat is handled by the OS, since text input is now decoupled from physical key events.
Sam Lantinga <slouken@libsdl.org>
parents:
2090
diff
changeset
|
390 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
|
391 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
|
392 SDL_SendKeyboardText(data->keyboard, text); |
2273 | 393 [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
|
394 } |
1959
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
395 } |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
396 break; |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
397 case NSKeyUp: |
2268
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
398 SDL_SendKeyboardKey(data->keyboard, SDL_RELEASED, (Uint8)scancode, physicalKey); |
1959
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
399 break; |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
400 case NSFlagsChanged: |
2268
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
401 /* 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
|
402 HandleModifiers(_this, scancode, [event modifierFlags]); |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
403 break; |
2268
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
404 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
|
405 break; |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
406 } |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
407 } |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
408 |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
409 SDLKey |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
410 Cocoa_GetLayoutKey(_THIS, SDLKey physicalKey) |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
411 { |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
412 switch (physicalKey) { |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
413 /* Many of these keys would generate a character in the translation by keyboard layout, but an inappropriate one, so we catch them before. */ |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
414 case SDLK_UNKNOWN: |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
415 case SDLK_RETURN: |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
416 case SDLK_ESCAPE: |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
417 case SDLK_BACKSPACE: |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
418 case SDLK_TAB: |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
419 case SDLK_SPACE: |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
420 case SDLK_CAPSLOCK: |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
421 case SDLK_F1: |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
422 case SDLK_F2: |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
423 case SDLK_F3: |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
424 case SDLK_F4: |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
425 case SDLK_F5: |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
426 case SDLK_F6: |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
427 case SDLK_F7: |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
428 case SDLK_F8: |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
429 case SDLK_F9: |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
430 case SDLK_F10: |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
431 case SDLK_F11: |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
432 case SDLK_F12: |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
433 case SDLK_PRINTSCREEN: |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
434 case SDLK_SCROLLLOCK: |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
435 case SDLK_PAUSE: |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
436 case SDLK_INSERT: |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
437 case SDLK_HOME: |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
438 case SDLK_PAGEUP: |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
439 case SDLK_DELETE: |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
440 case SDLK_END: |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
441 case SDLK_PAGEDOWN: |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
442 case SDLK_RIGHT: |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
443 case SDLK_LEFT: |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
444 case SDLK_DOWN: |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
445 case SDLK_UP: |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
446 case SDLK_KP_NUMLOCKCLEAR: |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
447 case SDLK_KP_ENTER: |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
448 case SDLK_APPLICATION: |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
449 case SDLK_POWER: |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
450 case SDLK_F13: |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
451 case SDLK_F14: |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
452 case SDLK_F15: |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
453 case SDLK_F16: |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
454 case SDLK_LCTRL: |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
455 case SDLK_LSHIFT: |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
456 case SDLK_LALT: |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
457 case SDLK_LMETA: |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
458 case SDLK_RCTRL: |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
459 case SDLK_RSHIFT: |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
460 case SDLK_RALT: |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
461 case SDLK_RMETA: |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
462 return physicalKey; |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
463 |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
464 /* For the rest, we try the translation first. */ |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
465 default: { |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
466 UInt16 vkey = 0; |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
467 KeyboardLayoutRef layout; |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
468 KeyboardLayoutKind kind; |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
469 UInt32 keyboardType = LMGetKbdType(); |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
470 |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
471 /* Look up pkey to get a Mac virtual key code - linear search isn't terribly efficient, this might have to be optimized. */ |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
472 while (vkey < 128 && physicalKey != macToSDLKey[vkey]) vkey++; |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
473 if (vkey == 128) return physicalKey; |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
474 if ((vkey == 10 || vkey == 50) && KBGetLayoutType(keyboardType) == kKeyboardISO) vkey = 60 - vkey; /* 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
|
475 |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
476 if (KLGetCurrentKeyboardLayout(&layout) != noErr) return physicalKey; |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
477 if (KLGetKeyboardLayoutProperty(layout, kKLKind, (const void **)&kind) != noErr) return physicalKey; |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
478 if (kind == kKLKCHRuchrKind || kind == kKLuchrKind) { |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
479 UniChar utf16String[4]; |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
480 UInt32 deadKeyState = 0; |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
481 UniCharCount actualStringLength; |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
482 const UCKeyboardLayout *uchrData; |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
483 |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
484 if (KLGetKeyboardLayoutProperty(layout, kKLuchrData, (const void **)&uchrData) != noErr) return physicalKey; |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
485 if (UCKeyTranslate(uchrData, vkey, kUCKeyActionDisplay, 0, keyboardType, 0, &deadKeyState, 4, &actualStringLength, utf16String) != noErr) return physicalKey; |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
486 /* kUCKeyActionDisplay (instead of kUCKeyActionDown) seems to take care of dead keys, so no need to check for that case and simulate a second key press */ |
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 if (actualStringLength == 0) return physicalKey; |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
489 |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
490 /* Decode the first character from UTF-16. I'm not sure if this is appropriate for keyboard layouts that generate more than 1 character, or if we would have to use SDL_KEY_LAYOUT_SPECIAL_BIT in that case. */ |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
491 if (utf16String[0] < 0xD800 || utf16String[0] > 0xDFFF) { |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
492 return utf16String[0]; |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
493 } |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
494 else if (utf16String[0] > 0xDBFF || utf16String[1] < 0xDC00 || utf16String[1] > 0xDFFF) { |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
495 /* invalid UTF-16 */ |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
496 return physicalKey; |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
497 } |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
498 else { |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
499 return (((utf16String[0] & 0x3FF) << 10) | (utf16String[1] & 0x3FF)) + 0x10000; |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
500 } |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
501 } |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
502 else { /* kind == kKLKCHRKind */ |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
503 const void *kchrData; |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
504 UInt32 state = 0; |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
505 UInt8 charCode; |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
506 SInt32 scriptCode; |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
507 TextEncoding keyboardEncoding; |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
508 CFStringRef conversionString; |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
509 UniChar codepoint; |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
510 |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
511 if (KLGetKeyboardLayoutProperty(layout, kKLKCHRData, &kchrData) != noErr) return physicalKey; |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
512 charCode = KeyTranslate(kchrData, vkey, &state) & 0xFF; /* Actually returns a UInt32 containing two character codes (and two 'reserved' bytes), but we're only interested in the second (or only) one */ |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
513 if (charCode == 0) { |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
514 /* It's a dead key, so simulate a second key press */ |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
515 charCode = KeyTranslate(kchrData, vkey, &state) & 0xFF; |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
516 /* Still zero? Give up. */ |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
517 if (charCode == 0) return physicalKey; |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
518 } |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
519 if (KLGetKeyboardLayoutProperty(layout, kKLGroupIdentifier, (const void **)&scriptCode) != noErr) return physicalKey; /* That the group identifier is actually a script code is not documented, but confirmed here: <http://lists.apple.com/archives/carbon-dev/2005/Jan/msg00533.html> */ |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
520 if (UpgradeScriptInfoToTextEncoding(scriptCode, kTextLanguageDontCare, kTextRegionDontCare, NULL, &keyboardEncoding) != noErr) return physicalKey; |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
521 |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
522 conversionString = CFStringCreateWithBytes(kCFAllocatorDefault, &charCode, 1, keyboardEncoding, FALSE); |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
523 codepoint = CFStringGetCharacterAtIndex(conversionString, 0); |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
524 CFRelease(conversionString); |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
525 return codepoint; |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
526 } |
4baee598306d
Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents:
2170
diff
changeset
|
527 } |
1959
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
528 } |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
529 } |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
530 |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1931
diff
changeset
|
531 void |
1931
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
532 Cocoa_QuitKeyboard(_THIS) |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
533 { |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
534 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
|
535 NSAutoreleasePool *pool; |
1931
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
536 |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
537 SDL_DelKeyboard(data->keyboard); |
2169
13cf2d5eda86
Added key composition support, courtesy of Kuon
Sam Lantinga <slouken@libsdl.org>
parents:
2129
diff
changeset
|
538 |
2270
d5a11262f067
Date: Sun, 19 Aug 2007 18:29:28 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
2268
diff
changeset
|
539 pool = [[NSAutoreleasePool alloc] init]; |
2169
13cf2d5eda86
Added key composition support, courtesy of Kuon
Sam Lantinga <slouken@libsdl.org>
parents:
2129
diff
changeset
|
540 [data->fieldEdit release]; |
2270
d5a11262f067
Date: Sun, 19 Aug 2007 18:29:28 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
2268
diff
changeset
|
541 [pool release]; |
1931
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
542 } |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
543 |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
544 /* vi: set ts=4 sw=4 expandtab: */ |