Changeset 56361 in webkit
- Timestamp:
- Mar 22, 2010 2:56:45 PM (14 years ago)
- Location:
- trunk/WebCore
- Files:
-
- 2 added
- 3 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebCore/ChangeLog
r56360 r56361 1 2010-03-22 Joseph Pecoraro <joepeck@webkit.org> 2 3 Reviewed by David Kilzer. 4 5 Upstream Part of the iPhone Platform sharing code with the Mac Platform 6 https://bugs.webkit.org/show_bug.cgi?id=35870 7 <rdar://problem/7707283> 8 9 Part 2 of 3: No changes other than moving code around. 10 Copied KeyEvent function from platform/mac to a platform/cocoa shared directory. 11 12 * WebCore.xcodeproj/project.pbxproj: Added cocoa group and new files. 13 * platform/cocoa/KeyEventCocoa.h: Added. 14 * platform/cocoa/KeyEventCocoa.mm: Copied from WebCore/platform/mac/KeyEventMac.mm. 15 (WebCore::keyIdentifierForKeyEvent): 16 (WebCore::windowsKeyCodeForKeyEvent): Include the shared code. 17 * platform/mac/KeyEventMac.mm: 18 1 19 2010-03-22 Joseph Pecoraro <joepeck@webkit.org> 2 20 -
trunk/WebCore/WebCore.xcodeproj/project.pbxproj
r56360 r56361 2494 2494 A43BF59C1149292800C643CA /* RenderProgress.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A43BF59A1149292800C643CA /* RenderProgress.cpp */; }; 2495 2495 A43BF59D1149292800C643CA /* RenderProgress.h in Headers */ = {isa = PBXBuildFile; fileRef = A43BF59B1149292800C643CA /* RenderProgress.h */; }; 2496 A513B3D7114B1666001C429B /* KeyEventCocoa.h in Headers */ = {isa = PBXBuildFile; fileRef = A5C974CF11485FF10066F2AB /* KeyEventCocoa.h */; }; 2497 A513B3D8114B166A001C429B /* KeyEventCocoa.mm in Sources */ = {isa = PBXBuildFile; fileRef = A5C974D011485FF10066F2AB /* KeyEventCocoa.mm */; }; 2496 2498 A59E3C1E11580F510072928E /* KeyEventCodesIPhone.h in Headers */ = {isa = PBXBuildFile; fileRef = A59E3C1C11580F510072928E /* KeyEventCodesIPhone.h */; }; 2497 2499 A59E3C1F11580F510072928E /* KeyEventIPhone.mm in Sources */ = {isa = PBXBuildFile; fileRef = A59E3C1D11580F510072928E /* KeyEventIPhone.mm */; }; … … 7906 7908 A5AFB34D115151A700B045CB /* StepRange.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = StepRange.cpp; sourceTree = "<group>"; }; 7907 7909 A5AFB34E115151A700B045CB /* StepRange.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StepRange.h; sourceTree = "<group>"; }; 7910 A5C974CF11485FF10066F2AB /* KeyEventCocoa.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = KeyEventCocoa.h; path = cocoa/KeyEventCocoa.h; sourceTree = "<group>"; }; 7911 A5C974D011485FF10066F2AB /* KeyEventCocoa.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = KeyEventCocoa.mm; path = cocoa/KeyEventCocoa.mm; sourceTree = "<group>"; }; 7908 7912 A718760D0B2A120100A16ECE /* DragActions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DragActions.h; sourceTree = "<group>"; }; 7909 7913 A718788F0B2D04AC00A16ECE /* DragControllerMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DragControllerMac.mm; sourceTree = "<group>"; }; … … 13216 13220 sourceTree = "<group>"; 13217 13221 }; 13222 A5C974CE11485FDA0066F2AB /* cocoa */ = { 13223 isa = PBXGroup; 13224 children = ( 13225 A5C974CF11485FF10066F2AB /* KeyEventCocoa.h */, 13226 A5C974D011485FF10066F2AB /* KeyEventCocoa.mm */, 13227 ); 13228 name = cocoa; 13229 sourceTree = "<group>"; 13230 }; 13218 13231 A75E8B7F0E1DE2B0007F2481 /* filters */ = { 13219 13232 isa = PBXGroup; … … 15301 15314 49E912A40EFAC8E6009D0CAF /* animation */, 15302 15315 1AE42F670AA4B8CB00C8612D /* cf */, 15316 A5C974CE11485FDA0066F2AB /* cocoa */, 15303 15317 B2A015910AF6CD53006BCE0E /* graphics */, 15304 15318 A59E3C1B11580F340072928E /* iphone */, … … 18727 18741 A5AFB350115151A700B045CB /* StepRange.h in Headers */, 18728 18742 A59E3C1E11580F510072928E /* KeyEventCodesIPhone.h in Headers */, 18743 A513B3D7114B1666001C429B /* KeyEventCocoa.h in Headers */, 18729 18744 ); 18730 18745 runOnlyForDeploymentPostprocessing = 0; … … 20937 20952 A5AFB34F115151A700B045CB /* StepRange.cpp in Sources */, 20938 20953 A59E3C1F11580F510072928E /* KeyEventIPhone.mm in Sources */, 20954 A513B3D8114B166A001C429B /* KeyEventCocoa.mm in Sources */, 20939 20955 ); 20940 20956 runOnlyForDeploymentPostprocessing = 0; -
trunk/WebCore/platform/cocoa/KeyEventCocoa.mm
r56360 r56361 1 1 /* 2 * Copyright (C) 2004, 2006, 2007, 20 10 Apple Inc.All rights reserved.2 * Copyright (C) 2004, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 21 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 24 */ 25 25 26 26 #import "config.h" 27 #import "PlatformKeyboardEvent.h" 28 29 #if PLATFORM(MAC) 27 #import "KeyEventCocoa.h" 30 28 31 29 #import "Logging.h" 32 #import <Carbon/Carbon.h>30 #import "PlatformString.h" 33 31 #import <wtf/ASCIICType.h> 34 32 … … 37 35 namespace WebCore { 38 36 39 staticString keyIdentifierForKeyEvent(NSEvent* event)37 String keyIdentifierForKeyEvent(NSEvent* event) 40 38 { 41 if ([event type] == NSFlagsChanged) 39 if ([event type] == NSFlagsChanged) 42 40 switch ([event keyCode]) { 43 41 case 54: // Right Command 44 42 case 55: // Left Command 45 43 return "Meta"; 46 44 47 45 case 57: // Capslock 48 46 return "CapsLock"; 49 47 50 48 case 56: // Left Shift 51 49 case 60: // Right Shift 52 50 return "Shift"; 53 51 54 52 case 58: // Left Alt 55 53 case 61: // Right Alt 56 54 return "Alt"; 57 55 58 56 case 59: // Left Ctrl 59 57 case 62: // Right Ctrl 60 58 return "Control"; 61 59 62 60 default: 63 61 ASSERT_NOT_REACHED(); 64 62 return ""; 65 63 } 66 64 67 65 NSString *s = [event charactersIgnoringModifiers]; 68 66 if ([s length] != 1) { … … 332 330 case NSDeleteFunctionKey: 333 331 return "U+007F"; 334 332 335 333 // Always use 0x09 for tab instead of AppKit's backtab character. 336 334 case NSBackTabCharacter: … … 359 357 } 360 358 361 static bool isKeypadEvent(NSEvent* event) 362 { 363 // Check that this is the type of event that has a keyCode. 364 switch ([event type]) { 365 case NSKeyDown: 366 case NSKeyUp: 367 case NSFlagsChanged: 368 break; 369 default: 370 return false; 371 } 372 373 if ([event modifierFlags] & NSNumericPadKeyMask) 374 return true; 375 376 switch ([event keyCode]) { 377 case 71: // Clear 378 case 81: // = 379 case 75: // / 380 case 67: // * 381 case 78: // - 382 case 69: // + 383 case 76: // Enter 384 case 65: // . 385 case 82: // 0 386 case 83: // 1 387 case 84: // 2 388 case 85: // 3 389 case 86: // 4 390 case 87: // 5 391 case 88: // 6 392 case 89: // 7 393 case 91: // 8 394 case 92: // 9 395 return true; 396 } 397 398 return false; 399 } 400 401 static int windowsKeyCodeForKeyEvent(NSEvent* event) 359 int windowsKeyCodeForKeyEvent(NSEvent* event) 402 360 { 403 361 switch ([event keyCode]) { … … 408 366 case 54: // Right Command 409 367 return 0x5D; 410 368 411 369 // VK_LWIN (5B) Left windows/meta key 412 370 case 55: // Left Command 413 371 return 0x5B; 414 372 415 373 // VK_CAPITAL (14) caps locks key 416 374 case 57: // Capslock 417 375 return 0x14; 418 376 419 377 // VK_SHIFT (10) either shift key 420 378 case 56: // Left Shift 421 379 case 60: // Right Shift 422 380 return 0x10; 423 381 424 382 // VK_MENU (12) either alt key 425 383 case 58: // Left Alt 426 384 case 61: // Right Alt 427 385 return 0x12; 428 386 429 387 // VK_CONTROL (11) either ctrl key 430 388 case 59: // Left Ctrl 431 389 case 62: // Right Ctrl 432 390 return 0x11; 433 391 434 392 // VK_CLEAR (0C) CLEAR key 435 393 case 71: return 0x0C; … … 767 725 } 768 726 769 static inline bool isKeyUpEvent(NSEvent *event)770 {771 if ([event type] != NSFlagsChanged)772 return [event type] == NSKeyUp;773 // FIXME: This logic fails if the user presses both Shift keys at once, for example:774 // we treat releasing one of them as keyDown.775 switch ([event keyCode]) {776 case 54: // Right Command777 case 55: // Left Command778 return ([event modifierFlags] & NSCommandKeyMask) == 0;779 780 case 57: // Capslock781 return ([event modifierFlags] & NSAlphaShiftKeyMask) == 0;782 783 case 56: // Left Shift784 case 60: // Right Shift785 return ([event modifierFlags] & NSShiftKeyMask) == 0;786 787 case 58: // Left Alt788 case 61: // Right Alt789 return ([event modifierFlags] & NSAlternateKeyMask) == 0;790 791 case 59: // Left Ctrl792 case 62: // Right Ctrl793 return ([event modifierFlags] & NSControlKeyMask) == 0;794 795 case 63: // Function796 return ([event modifierFlags] & NSFunctionKeyMask) == 0;797 }798 return false;799 727 } 800 801 static inline String textFromEvent(NSEvent* event)802 {803 if ([event type] == NSFlagsChanged)804 return "";805 return [event characters];806 }807 808 809 static inline String unmodifiedTextFromEvent(NSEvent* event)810 {811 if ([event type] == NSFlagsChanged)812 return "";813 return [event charactersIgnoringModifiers];814 }815 816 PlatformKeyboardEvent::PlatformKeyboardEvent(NSEvent *event)817 : m_type(isKeyUpEvent(event) ? PlatformKeyboardEvent::KeyUp : PlatformKeyboardEvent::KeyDown)818 , m_text(textFromEvent(event))819 , m_unmodifiedText(unmodifiedTextFromEvent(event))820 , m_keyIdentifier(keyIdentifierForKeyEvent(event))821 , m_autoRepeat(([event type] != NSFlagsChanged) && [event isARepeat])822 , m_windowsVirtualKeyCode(windowsKeyCodeForKeyEvent(event))823 , m_nativeVirtualKeyCode([event keyCode])824 , m_isKeypad(isKeypadEvent(event))825 , m_shiftKey([event modifierFlags] & NSShiftKeyMask)826 , m_ctrlKey([event modifierFlags] & NSControlKeyMask)827 , m_altKey([event modifierFlags] & NSAlternateKeyMask)828 , m_metaKey([event modifierFlags] & NSCommandKeyMask)829 , m_macEvent(event)830 {831 // Always use 13 for Enter/Return -- we don't want to use AppKit's different character for Enter.832 if (m_windowsVirtualKeyCode == '\r') {833 m_text = "\r";834 m_unmodifiedText = "\r";835 }836 837 // The adjustments below are only needed in backward compatibility mode, but we cannot tell what mode we are in from here.838 839 // Turn 0x7F into 8, because backspace needs to always be 8.840 if (m_text == "\x7F")841 m_text = "\x8";842 if (m_unmodifiedText == "\x7F")843 m_unmodifiedText = "\x8";844 // Always use 9 for tab -- we don't want to use AppKit's different character for shift-tab.845 if (m_windowsVirtualKeyCode == 9) {846 m_text = "\x9";847 m_unmodifiedText = "\x9";848 }849 }850 851 void PlatformKeyboardEvent::disambiguateKeyDownEvent(Type type, bool backwardCompatibilityMode)852 {853 // Can only change type from KeyDown to RawKeyDown or Char, as we lack information for other conversions.854 ASSERT(m_type == KeyDown);855 ASSERT(type == RawKeyDown || type == Char);856 m_type = type;857 if (backwardCompatibilityMode)858 return;859 860 if (type == RawKeyDown) {861 m_text = String();862 m_unmodifiedText = String();863 } else {864 m_keyIdentifier = String();865 m_windowsVirtualKeyCode = 0;866 if (m_text.length() == 1 && (m_text[0U] >= 0xF700 && m_text[0U] <= 0xF7FF)) {867 // According to NSEvents.h, OpenStep reserves the range 0xF700-0xF8FF for function keys. However, some actual private use characters868 // happen to be in this range, e.g. the Apple logo (Option+Shift+K).869 // 0xF7FF is an arbitrary cut-off.870 m_text = String();871 m_unmodifiedText = String();872 }873 }874 }875 876 bool PlatformKeyboardEvent::currentCapsLockState()877 {878 return GetCurrentKeyModifiers() & alphaLock;879 }880 881 void PlatformKeyboardEvent::getCurrentModifierState(bool& shiftKey, bool& ctrlKey, bool& altKey, bool& metaKey)882 {883 UInt32 currentModifiers = GetCurrentKeyModifiers();884 shiftKey = currentModifiers & ::shiftKey;885 ctrlKey = currentModifiers & ::controlKey;886 altKey = currentModifiers & ::optionKey;887 metaKey = currentModifiers & ::cmdKey;888 }889 890 }891 892 #endif // PLATFORM(MAC) -
trunk/WebCore/platform/mac/KeyEventMac.mm
r56360 r56361 29 29 #if PLATFORM(MAC) 30 30 31 #import "KeyEventCocoa.h" 31 32 #import "Logging.h" 32 33 #import <Carbon/Carbon.h> … … 36 37 37 38 namespace WebCore { 38 39 static String keyIdentifierForKeyEvent(NSEvent* event)40 {41 if ([event type] == NSFlagsChanged)42 switch ([event keyCode]) {43 case 54: // Right Command44 case 55: // Left Command45 return "Meta";46 47 case 57: // Capslock48 return "CapsLock";49 50 case 56: // Left Shift51 case 60: // Right Shift52 return "Shift";53 54 case 58: // Left Alt55 case 61: // Right Alt56 return "Alt";57 58 case 59: // Left Ctrl59 case 62: // Right Ctrl60 return "Control";61 62 default:63 ASSERT_NOT_REACHED();64 return "";65 }66 67 NSString *s = [event charactersIgnoringModifiers];68 if ([s length] != 1) {69 LOG(Events, "received an unexpected number of characters in key event: %u", [s length]);70 return "Unidentified";71 }72 unichar c = [s characterAtIndex:0];73 switch (c) {74 // Each identifier listed in the DOM spec is listed here.75 // Many are simply commented out since they do not appear on standard Macintosh keyboards76 // or are on a key that doesn't have a corresponding character.77 78 // "Accept"79 // "AllCandidates"80 81 // "Alt"82 case NSMenuFunctionKey:83 return "Alt";84 85 // "Apps"86 // "BrowserBack"87 // "BrowserForward"88 // "BrowserHome"89 // "BrowserRefresh"90 // "BrowserSearch"91 // "BrowserStop"92 // "CapsLock"93 94 // "Clear"95 case NSClearLineFunctionKey:96 return "Clear";97 98 // "CodeInput"99 // "Compose"100 // "Control"101 // "Crsel"102 // "Convert"103 // "Copy"104 // "Cut"105 106 // "Down"107 case NSDownArrowFunctionKey:108 return "Down";109 // "End"110 case NSEndFunctionKey:111 return "End";112 // "Enter"113 case 0x3: case 0xA: case 0xD: // Macintosh calls the one on the main keyboard Return, but Windows calls it Enter, so we'll do the same for the DOM114 return "Enter";115 116 // "EraseEof"117 118 // "Execute"119 case NSExecuteFunctionKey:120 return "Execute";121 122 // "Exsel"123 124 // "F1"125 case NSF1FunctionKey:126 return "F1";127 // "F2"128 case NSF2FunctionKey:129 return "F2";130 // "F3"131 case NSF3FunctionKey:132 return "F3";133 // "F4"134 case NSF4FunctionKey:135 return "F4";136 // "F5"137 case NSF5FunctionKey:138 return "F5";139 // "F6"140 case NSF6FunctionKey:141 return "F6";142 // "F7"143 case NSF7FunctionKey:144 return "F7";145 // "F8"146 case NSF8FunctionKey:147 return "F8";148 // "F9"149 case NSF9FunctionKey:150 return "F9";151 // "F10"152 case NSF10FunctionKey:153 return "F10";154 // "F11"155 case NSF11FunctionKey:156 return "F11";157 // "F12"158 case NSF12FunctionKey:159 return "F12";160 // "F13"161 case NSF13FunctionKey:162 return "F13";163 // "F14"164 case NSF14FunctionKey:165 return "F14";166 // "F15"167 case NSF15FunctionKey:168 return "F15";169 // "F16"170 case NSF16FunctionKey:171 return "F16";172 // "F17"173 case NSF17FunctionKey:174 return "F17";175 // "F18"176 case NSF18FunctionKey:177 return "F18";178 // "F19"179 case NSF19FunctionKey:180 return "F19";181 // "F20"182 case NSF20FunctionKey:183 return "F20";184 // "F21"185 case NSF21FunctionKey:186 return "F21";187 // "F22"188 case NSF22FunctionKey:189 return "F22";190 // "F23"191 case NSF23FunctionKey:192 return "F23";193 // "F24"194 case NSF24FunctionKey:195 return "F24";196 197 // "FinalMode"198 199 // "Find"200 case NSFindFunctionKey:201 return "Find";202 203 // "FullWidth"204 // "HalfWidth"205 // "HangulMode"206 // "HanjaMode"207 208 // "Help"209 case NSHelpFunctionKey:210 return "Help";211 212 // "Hiragana"213 214 // "Home"215 case NSHomeFunctionKey:216 return "Home";217 // "Insert"218 case NSInsertFunctionKey:219 return "Insert";220 221 // "JapaneseHiragana"222 // "JapaneseKatakana"223 // "JapaneseRomaji"224 // "JunjaMode"225 // "KanaMode"226 // "KanjiMode"227 // "Katakana"228 // "LaunchApplication1"229 // "LaunchApplication2"230 // "LaunchMail"231 232 // "Left"233 case NSLeftArrowFunctionKey:234 return "Left";235 236 // "Meta"237 // "MediaNextTrack"238 // "MediaPlayPause"239 // "MediaPreviousTrack"240 // "MediaStop"241 242 // "ModeChange"243 case NSModeSwitchFunctionKey:244 return "ModeChange";245 246 // "Nonconvert"247 // "NumLock"248 249 // "PageDown"250 case NSPageDownFunctionKey:251 return "PageDown";252 // "PageUp"253 case NSPageUpFunctionKey:254 return "PageUp";255 256 // "Paste"257 258 // "Pause"259 case NSPauseFunctionKey:260 return "Pause";261 262 // "Play"263 // "PreviousCandidate"264 265 // "PrintScreen"266 case NSPrintScreenFunctionKey:267 return "PrintScreen";268 269 // "Process"270 // "Props"271 272 // "Right"273 case NSRightArrowFunctionKey:274 return "Right";275 276 // "RomanCharacters"277 278 // "Scroll"279 case NSScrollLockFunctionKey:280 return "Scroll";281 // "Select"282 case NSSelectFunctionKey:283 return "Select";284 285 // "SelectMedia"286 // "Shift"287 288 // "Stop"289 case NSStopFunctionKey:290 return "Stop";291 // "Up"292 case NSUpArrowFunctionKey:293 return "Up";294 // "Undo"295 case NSUndoFunctionKey:296 return "Undo";297 298 // "VolumeDown"299 // "VolumeMute"300 // "VolumeUp"301 // "Win"302 // "Zoom"303 304 // More function keys, not in the key identifier specification.305 case NSF25FunctionKey:306 return "F25";307 case NSF26FunctionKey:308 return "F26";309 case NSF27FunctionKey:310 return "F27";311 case NSF28FunctionKey:312 return "F28";313 case NSF29FunctionKey:314 return "F29";315 case NSF30FunctionKey:316 return "F30";317 case NSF31FunctionKey:318 return "F31";319 case NSF32FunctionKey:320 return "F32";321 case NSF33FunctionKey:322 return "F33";323 case NSF34FunctionKey:324 return "F34";325 case NSF35FunctionKey:326 return "F35";327 328 // Turn 0x7F into 0x08, because backspace needs to always be 0x08.329 case 0x7F:330 return "U+0008";331 // Standard says that DEL becomes U+007F.332 case NSDeleteFunctionKey:333 return "U+007F";334 335 // Always use 0x09 for tab instead of AppKit's backtab character.336 case NSBackTabCharacter:337 return "U+0009";338 339 case NSBeginFunctionKey:340 case NSBreakFunctionKey:341 case NSClearDisplayFunctionKey:342 case NSDeleteCharFunctionKey:343 case NSDeleteLineFunctionKey:344 case NSInsertCharFunctionKey:345 case NSInsertLineFunctionKey:346 case NSNextFunctionKey:347 case NSPrevFunctionKey:348 case NSPrintFunctionKey:349 case NSRedoFunctionKey:350 case NSResetFunctionKey:351 case NSSysReqFunctionKey:352 case NSSystemFunctionKey:353 case NSUserFunctionKey:354 // FIXME: We should use something other than the vendor-area Unicode values for the above keys.355 // For now, just fall through to the default.356 default:357 return String::format("U+%04X", toASCIIUpper(c));358 }359 }360 39 361 40 static bool isKeypadEvent(NSEvent* event) … … 399 78 } 400 79 401 static int windowsKeyCodeForKeyEvent(NSEvent* event)402 {403 switch ([event keyCode]) {404 // VK_TAB (09) TAB key405 case 48: return 0x09;406 407 // VK_APPS (5D) Right windows/meta key408 case 54: // Right Command409 return 0x5D;410 411 // VK_LWIN (5B) Left windows/meta key412 case 55: // Left Command413 return 0x5B;414 415 // VK_CAPITAL (14) caps locks key416 case 57: // Capslock417 return 0x14;418 419 // VK_SHIFT (10) either shift key420 case 56: // Left Shift421 case 60: // Right Shift422 return 0x10;423 424 // VK_MENU (12) either alt key425 case 58: // Left Alt426 case 61: // Right Alt427 return 0x12;428 429 // VK_CONTROL (11) either ctrl key430 case 59: // Left Ctrl431 case 62: // Right Ctrl432 return 0x11;433 434 // VK_CLEAR (0C) CLEAR key435 case 71: return 0x0C;436 437 // VK_NUMPAD0 (60) Numeric keypad 0 key438 case 82: return 0x60;439 // VK_NUMPAD1 (61) Numeric keypad 1 key440 case 83: return 0x61;441 // VK_NUMPAD2 (62) Numeric keypad 2 key442 case 84: return 0x62;443 // VK_NUMPAD3 (63) Numeric keypad 3 key444 case 85: return 0x63;445 // VK_NUMPAD4 (64) Numeric keypad 4 key446 case 86: return 0x64;447 // VK_NUMPAD5 (65) Numeric keypad 5 key448 case 87: return 0x65;449 // VK_NUMPAD6 (66) Numeric keypad 6 key450 case 88: return 0x66;451 // VK_NUMPAD7 (67) Numeric keypad 7 key452 case 89: return 0x67;453 // VK_NUMPAD8 (68) Numeric keypad 8 key454 case 91: return 0x68;455 // VK_NUMPAD9 (69) Numeric keypad 9 key456 case 92: return 0x69;457 // VK_MULTIPLY (6A) Multiply key458 case 67: return 0x6A;459 // VK_ADD (6B) Add key460 case 69: return 0x6B;461 462 // VK_SUBTRACT (6D) Subtract key463 case 78: return 0x6D;464 // VK_DECIMAL (6E) Decimal key465 case 65: return 0x6E;466 // VK_DIVIDE (6F) Divide key467 case 75: return 0x6F;468 }469 470 NSString* s = [event charactersIgnoringModifiers];471 if ([s length] != 1)472 return 0;473 474 switch ([s characterAtIndex:0]) {475 // VK_LBUTTON (01) Left mouse button476 // VK_RBUTTON (02) Right mouse button477 // VK_CANCEL (03) Control-break processing478 // VK_MBUTTON (04) Middle mouse button (three-button mouse)479 // VK_XBUTTON1 (05)480 // VK_XBUTTON2 (06)481 482 // VK_BACK (08) BACKSPACE key483 case 8: case 0x7F: return 0x08;484 // VK_TAB (09) TAB key485 case 9: return 0x09;486 487 // VK_CLEAR (0C) CLEAR key488 // handled by key code above489 490 // VK_RETURN (0D)491 case 0xD: case 3: return 0x0D;492 493 // VK_SHIFT (10) SHIFT key494 // VK_CONTROL (11) CTRL key495 // VK_MENU (12) ALT key496 497 // VK_PAUSE (13) PAUSE key498 case NSPauseFunctionKey: return 0x13;499 500 // VK_CAPITAL (14) CAPS LOCK key501 // VK_KANA (15) Input Method Editor (IME) Kana mode502 // VK_HANGUEL (15) IME Hanguel mode (maintained for compatibility; use VK_HANGUL)503 // VK_HANGUL (15) IME Hangul mode504 // VK_JUNJA (17) IME Junja mode505 // VK_FINAL (18) IME final mode506 // VK_HANJA (19) IME Hanja mode507 // VK_KANJI (19) IME Kanji mode508 509 // VK_ESCAPE (1B) ESC key510 case 0x1B: return 0x1B;511 512 // VK_CONVERT (1C) IME convert513 // VK_NONCONVERT (1D) IME nonconvert514 // VK_ACCEPT (1E) IME accept515 // VK_MODECHANGE (1F) IME mode change request516 517 // VK_SPACE (20) SPACEBAR518 case ' ': return 0x20;519 // VK_PRIOR (21) PAGE UP key520 case NSPageUpFunctionKey: return 0x21;521 // VK_NEXT (22) PAGE DOWN key522 case NSPageDownFunctionKey: return 0x22;523 // VK_END (23) END key524 case NSEndFunctionKey: return 0x23;525 // VK_HOME (24) HOME key526 case NSHomeFunctionKey: return 0x24;527 // VK_LEFT (25) LEFT ARROW key528 case NSLeftArrowFunctionKey: return 0x25;529 // VK_UP (26) UP ARROW key530 case NSUpArrowFunctionKey: return 0x26;531 // VK_RIGHT (27) RIGHT ARROW key532 case NSRightArrowFunctionKey: return 0x27;533 // VK_DOWN (28) DOWN ARROW key534 case NSDownArrowFunctionKey: return 0x28;535 // VK_SELECT (29) SELECT key536 case NSSelectFunctionKey: return 0x29;537 // VK_PRINT (2A) PRINT key538 case NSPrintFunctionKey: return 0x2A;539 // VK_EXECUTE (2B) EXECUTE key540 case NSExecuteFunctionKey: return 0x2B;541 // VK_SNAPSHOT (2C) PRINT SCREEN key542 case NSPrintScreenFunctionKey: return 0x2C;543 // VK_INSERT (2D) INS key544 case NSInsertFunctionKey: case NSHelpFunctionKey: return 0x2D;545 // VK_DELETE (2E) DEL key546 case NSDeleteFunctionKey: return 0x2E;547 548 // VK_HELP (2F) HELP key549 550 // (30) 0 key551 case '0': case ')': return 0x30;552 // (31) 1 key553 case '1': case '!': return 0x31;554 // (32) 2 key555 case '2': case '@': return 0x32;556 // (33) 3 key557 case '3': case '#': return 0x33;558 // (34) 4 key559 case '4': case '$': return 0x34;560 // (35) 5 key561 case '5': case '%': return 0x35;562 // (36) 6 key563 case '6': case '^': return 0x36;564 // (37) 7 key565 case '7': case '&': return 0x37;566 // (38) 8 key567 case '8': case '*': return 0x38;568 // (39) 9 key569 case '9': case '(': return 0x39;570 // (41) A key571 case 'a': case 'A': return 0x41;572 // (42) B key573 case 'b': case 'B': return 0x42;574 // (43) C key575 case 'c': case 'C': return 0x43;576 // (44) D key577 case 'd': case 'D': return 0x44;578 // (45) E key579 case 'e': case 'E': return 0x45;580 // (46) F key581 case 'f': case 'F': return 0x46;582 // (47) G key583 case 'g': case 'G': return 0x47;584 // (48) H key585 case 'h': case 'H': return 0x48;586 // (49) I key587 case 'i': case 'I': return 0x49;588 // (4A) J key589 case 'j': case 'J': return 0x4A;590 // (4B) K key591 case 'k': case 'K': return 0x4B;592 // (4C) L key593 case 'l': case 'L': return 0x4C;594 // (4D) M key595 case 'm': case 'M': return 0x4D;596 // (4E) N key597 case 'n': case 'N': return 0x4E;598 // (4F) O key599 case 'o': case 'O': return 0x4F;600 // (50) P key601 case 'p': case 'P': return 0x50;602 // (51) Q key603 case 'q': case 'Q': return 0x51;604 // (52) R key605 case 'r': case 'R': return 0x52;606 // (53) S key607 case 's': case 'S': return 0x53;608 // (54) T key609 case 't': case 'T': return 0x54;610 // (55) U key611 case 'u': case 'U': return 0x55;612 // (56) V key613 case 'v': case 'V': return 0x56;614 // (57) W key615 case 'w': case 'W': return 0x57;616 // (58) X key617 case 'x': case 'X': return 0x58;618 // (59) Y key619 case 'y': case 'Y': return 0x59;620 // (5A) Z key621 case 'z': case 'Z': return 0x5A;622 623 // VK_LWIN (5B) Left Windows key (Microsoft Natural keyboard)624 // VK_RWIN (5C) Right Windows key (Natural keyboard)625 // VK_APPS (5D) Applications key (Natural keyboard)626 // VK_SLEEP (5F) Computer Sleep key627 628 // VK_NUMPAD0 (60) Numeric keypad 0 key629 // VK_NUMPAD1 (61) Numeric keypad 1 key630 // VK_NUMPAD2 (62) Numeric keypad 2 key631 // VK_NUMPAD3 (63) Numeric keypad 3 key632 // VK_NUMPAD4 (64) Numeric keypad 4 key633 // VK_NUMPAD5 (65) Numeric keypad 5 key634 // VK_NUMPAD6 (66) Numeric keypad 6 key635 // VK_NUMPAD7 (67) Numeric keypad 7 key636 // VK_NUMPAD8 (68) Numeric keypad 8 key637 // VK_NUMPAD9 (69) Numeric keypad 9 key638 // VK_MULTIPLY (6A) Multiply key639 // VK_ADD (6B) Add key640 // handled by key code above641 642 // VK_SEPARATOR (6C) Separator key643 644 // VK_SUBTRACT (6D) Subtract key645 // VK_DECIMAL (6E) Decimal key646 // VK_DIVIDE (6F) Divide key647 // handled by key code above648 649 // VK_F1 (70) F1 key650 case NSF1FunctionKey: return 0x70;651 // VK_F2 (71) F2 key652 case NSF2FunctionKey: return 0x71;653 // VK_F3 (72) F3 key654 case NSF3FunctionKey: return 0x72;655 // VK_F4 (73) F4 key656 case NSF4FunctionKey: return 0x73;657 // VK_F5 (74) F5 key658 case NSF5FunctionKey: return 0x74;659 // VK_F6 (75) F6 key660 case NSF6FunctionKey: return 0x75;661 // VK_F7 (76) F7 key662 case NSF7FunctionKey: return 0x76;663 // VK_F8 (77) F8 key664 case NSF8FunctionKey: return 0x77;665 // VK_F9 (78) F9 key666 case NSF9FunctionKey: return 0x78;667 // VK_F10 (79) F10 key668 case NSF10FunctionKey: return 0x79;669 // VK_F11 (7A) F11 key670 case NSF11FunctionKey: return 0x7A;671 // VK_F12 (7B) F12 key672 case NSF12FunctionKey: return 0x7B;673 // VK_F13 (7C) F13 key674 case NSF13FunctionKey: return 0x7C;675 // VK_F14 (7D) F14 key676 case NSF14FunctionKey: return 0x7D;677 // VK_F15 (7E) F15 key678 case NSF15FunctionKey: return 0x7E;679 // VK_F16 (7F) F16 key680 case NSF16FunctionKey: return 0x7F;681 // VK_F17 (80H) F17 key682 case NSF17FunctionKey: return 0x80;683 // VK_F18 (81H) F18 key684 case NSF18FunctionKey: return 0x81;685 // VK_F19 (82H) F19 key686 case NSF19FunctionKey: return 0x82;687 // VK_F20 (83H) F20 key688 case NSF20FunctionKey: return 0x83;689 // VK_F21 (84H) F21 key690 case NSF21FunctionKey: return 0x84;691 // VK_F22 (85H) F22 key692 case NSF22FunctionKey: return 0x85;693 // VK_F23 (86H) F23 key694 case NSF23FunctionKey: return 0x86;695 // VK_F24 (87H) F24 key696 case NSF24FunctionKey: return 0x87;697 698 // VK_NUMLOCK (90) NUM LOCK key699 700 // VK_SCROLL (91) SCROLL LOCK key701 case NSScrollLockFunctionKey: return 0x91;702 703 // VK_LSHIFT (A0) Left SHIFT key704 // VK_RSHIFT (A1) Right SHIFT key705 // VK_LCONTROL (A2) Left CONTROL key706 // VK_RCONTROL (A3) Right CONTROL key707 // VK_LMENU (A4) Left MENU key708 // VK_RMENU (A5) Right MENU key709 // VK_BROWSER_BACK (A6) Windows 2000/XP: Browser Back key710 // VK_BROWSER_FORWARD (A7) Windows 2000/XP: Browser Forward key711 // VK_BROWSER_REFRESH (A8) Windows 2000/XP: Browser Refresh key712 // VK_BROWSER_STOP (A9) Windows 2000/XP: Browser Stop key713 // VK_BROWSER_SEARCH (AA) Windows 2000/XP: Browser Search key714 // VK_BROWSER_FAVORITES (AB) Windows 2000/XP: Browser Favorites key715 // VK_BROWSER_HOME (AC) Windows 2000/XP: Browser Start and Home key716 // VK_VOLUME_MUTE (AD) Windows 2000/XP: Volume Mute key717 // VK_VOLUME_DOWN (AE) Windows 2000/XP: Volume Down key718 // VK_VOLUME_UP (AF) Windows 2000/XP: Volume Up key719 // VK_MEDIA_NEXT_TRACK (B0) Windows 2000/XP: Next Track key720 // VK_MEDIA_PREV_TRACK (B1) Windows 2000/XP: Previous Track key721 // VK_MEDIA_STOP (B2) Windows 2000/XP: Stop Media key722 // VK_MEDIA_PLAY_PAUSE (B3) Windows 2000/XP: Play/Pause Media key723 // VK_LAUNCH_MAIL (B4) Windows 2000/XP: Start Mail key724 // VK_LAUNCH_MEDIA_SELECT (B5) Windows 2000/XP: Select Media key725 // VK_LAUNCH_APP1 (B6) Windows 2000/XP: Start Application 1 key726 // VK_LAUNCH_APP2 (B7) Windows 2000/XP: Start Application 2 key727 728 // VK_OEM_1 (BA) Used for miscellaneous characters; it can vary by keyboard. Windows 2000/XP: For the US standard keyboard, the ';:' key729 case ';': case ':': return 0xBA;730 // VK_OEM_PLUS (BB) Windows 2000/XP: For any country/region, the '+' key731 case '=': case '+': return 0xBB;732 // VK_OEM_COMMA (BC) Windows 2000/XP: For any country/region, the ',' key733 case ',': case '<': return 0xBC;734 // VK_OEM_MINUS (BD) Windows 2000/XP: For any country/region, the '-' key735 case '-': case '_': return 0xBD;736 // VK_OEM_PERIOD (BE) Windows 2000/XP: For any country/region, the '.' key737 case '.': case '>': return 0xBE;738 // VK_OEM_2 (BF) Used for miscellaneous characters; it can vary by keyboard. Windows 2000/XP: For the US standard keyboard, the '/?' key739 case '/': case '?': return 0xBF;740 // VK_OEM_3 (C0) Used for miscellaneous characters; it can vary by keyboard. Windows 2000/XP: For the US standard keyboard, the '`~' key741 case '`': case '~': return 0xC0;742 // VK_OEM_4 (DB) Used for miscellaneous characters; it can vary by keyboard. Windows 2000/XP: For the US standard keyboard, the '[{' key743 case '[': case '{': return 0xDB;744 // VK_OEM_5 (DC) Used for miscellaneous characters; it can vary by keyboard. Windows 2000/XP: For the US standard keyboard, the '\|' key745 case '\\': case '|': return 0xDC;746 // VK_OEM_6 (DD) Used for miscellaneous characters; it can vary by keyboard. Windows 2000/XP: For the US standard keyboard, the ']}' key747 case ']': case '}': return 0xDD;748 // VK_OEM_7 (DE) Used for miscellaneous characters; it can vary by keyboard. Windows 2000/XP: For the US standard keyboard, the 'single-quote/double-quote' key749 case '\'': case '"': return 0xDE;750 751 // VK_OEM_8 (DF) Used for miscellaneous characters; it can vary by keyboard.752 // VK_OEM_102 (E2) Windows 2000/XP: Either the angle bracket key or the backslash key on the RT 102-key keyboard753 // VK_PROCESSKEY (E5) Windows 95/98/Me, Windows NT 4.0, Windows 2000/XP: IME PROCESS key754 // VK_PACKET (E7) Windows 2000/XP: Used to pass Unicode characters as if they were keystrokes. The VK_PACKET key is the low word of a 32-bit Virtual Key value used for non-keyboard input methods. For more information, see Remark in KEYBDINPUT,SendInput, WM_KEYDOWN, and WM_KEYUP755 // VK_ATTN (F6) Attn key756 // VK_CRSEL (F7) CrSel key757 // VK_EXSEL (F8) ExSel key758 // VK_EREOF (F9) Erase EOF key759 // VK_PLAY (FA) Play key760 // VK_ZOOM (FB) Zoom key761 // VK_NONAME (FC) Reserved for future use762 // VK_PA1 (FD) PA1 key763 // VK_OEM_CLEAR (FE) Clear key764 }765 766 return 0;767 }768 769 80 static inline bool isKeyUpEvent(NSEvent *event) 770 81 {
Note: See TracChangeset
for help on using the changeset viewer.