00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef OSDL_KEYBOARD_HANDLER_H_
00028 #define OSDL_KEYBOARD_HANDLER_H_
00029
00030
00031 #include "OSDLInputDeviceHandler.h"
00032 #include "OSDLEventsCommon.h"
00033 #include "OSDLEvents.h"
00034
00035 #include "Ceylan.h"
00036
00037
00038 #if ! defined(OSDL_USES_SDL) || OSDL_USES_SDL
00039 #include "SDL.h"
00040 #endif // OSDL_USES_SDL
00041
00042
00043 #if defined(OSDL_ARCH_NINTENDO_DS) && OSDL_ARCH_NINTENDO_DS
00044 #include "OSDLConfigForNintendoDS.h"
00045 #endif // OSDL_ARCH_NINTENDO_DS
00046
00047
00048 #include <string>
00049 #include <list>
00050 #include <map>
00051
00052
00053
00054
00055 namespace OSDL
00056 {
00057
00058
00059
00060 namespace MVC
00061 {
00062
00063
00064
00065
00066
00067
00068 class Controller ;
00069
00070 }
00071
00072
00073
00074 namespace Events
00075 {
00076
00077
00078
00092 typedef void (* KeyboardEventHandler)(
00093 const KeyboardEvent & keyboardEvent ) ;
00094
00095
00096
00098 class OSDL_DLL KeyboardException : public EventsException
00099 {
00100
00101 public:
00102 explicit KeyboardException( const std::string & reason ) ;
00103
00104 virtual ~KeyboardException() throw() ;
00105
00106 } ;
00107
00108
00109
00110
00131 enum KeyboardMode { rawInput, textInput } ;
00132
00133
00134
00135
00147 class OSDL_DLL KeyboardHandler : public InputDeviceHandler
00148 {
00149
00150
00151
00152
00153
00154
00155
00156 friend class OSDL::Events::EventsModule ;
00157
00158
00159
00160 public:
00161
00162
00163
00180 enum KeyIdentifier
00181 {
00182
00183
00184 #if ! defined(OSDL_USES_SDL) || OSDL_USES_SDL
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197 BackspaceKey = SDLK_BACKSPACE ,
00198 TabKey = SDLK_TAB ,
00199 ClearKey = SDLK_CLEAR ,
00200
00201
00202 EnterKey = SDLK_RETURN ,
00203
00204
00205 ReturnKey = SDLK_RETURN ,
00206
00207 PauseKey = SDLK_PAUSE ,
00208 EscapeKey = SDLK_ESCAPE ,
00209 SpaceKey = SDLK_SPACE ,
00210 ExclaimKey = SDLK_EXCLAIM ,
00211 QuotedBLKey = SDLK_QUOTEDBL ,
00212 HashKey = SDLK_HASH ,
00213 DollarKey = SDLK_DOLLAR ,
00214 AmpersandKey = SDLK_AMPERSAND ,
00215 QuoteKey = SDLK_QUOTE ,
00216 LeftParenthesisKey = SDLK_LEFTPAREN ,
00217 RightParenthesisKey = SDLK_RIGHTPAREN ,
00218 AsteriskKey = SDLK_ASTERISK ,
00219 PlusKey = SDLK_PLUS ,
00220 CommaKey = SDLK_COMMA ,
00221 MinusKey = SDLK_MINUS ,
00222 PeriodKey = SDLK_PERIOD ,
00223 SlashKey = SDLK_SLASH ,
00224 ZeroKey = SDLK_0 ,
00225 OneKey = SDLK_1 ,
00226 TwoKey = SDLK_2 ,
00227 ThreeKey = SDLK_3 ,
00228 FourKey = SDLK_4 ,
00229 FiveKey = SDLK_5 ,
00230 SixKey = SDLK_6 ,
00231 SevenKey = SDLK_7 ,
00232 HeightKey = SDLK_8 ,
00233 NineKey = SDLK_9 ,
00234 ColonKey = SDLK_COLON ,
00235 SemiColonKey = SDLK_SEMICOLON ,
00236 LessKey = SDLK_LESS ,
00237 EqualsKey = SDLK_EQUALS ,
00238 GreaterKey = SDLK_GREATER ,
00239 QuestionKey = SDLK_QUESTION ,
00240 AtKey = SDLK_AT ,
00241
00242
00243
00244
00245 LeftBracketKey = SDLK_LEFTBRACKET ,
00246 RightBracket = SDLK_RIGHTBRACKET ,
00247 BackslashKey = SDLK_BACKSLASH ,
00248 Caret = SDLK_CARET ,
00249 Underscore = SDLK_UNDERSCORE ,
00250 BackQuote = SDLK_BACKQUOTE ,
00251 aKey = SDLK_a ,
00252 bKey = SDLK_b ,
00253 cKey = SDLK_c ,
00254 dKey = SDLK_d ,
00255 eKey = SDLK_e ,
00256 fKey = SDLK_f ,
00257 gKey = SDLK_g ,
00258 hKey = SDLK_h ,
00259 iKey = SDLK_i ,
00260 jKey = SDLK_j ,
00261 kKey = SDLK_k ,
00262 lKey = SDLK_l ,
00263 mKey = SDLK_m ,
00264 nKey = SDLK_n ,
00265 oKey = SDLK_o ,
00266 pKey = SDLK_p ,
00267 qKey = SDLK_q ,
00268 rKey = SDLK_r ,
00269 sKey = SDLK_s ,
00270 tKey = SDLK_t ,
00271 uKey = SDLK_u ,
00272 vKey = SDLK_v ,
00273 wKey = SDLK_w ,
00274 xKey = SDLK_x ,
00275 yKey = SDLK_y ,
00276 zKey = SDLK_z ,
00277 DeleteKey = SDLK_DELETE ,
00278
00279
00280
00281
00282
00283
00284 International0Key = SDLK_WORLD_0 ,
00285 International1Key = SDLK_WORLD_1 ,
00286 International2Key = SDLK_WORLD_2 ,
00287 International3Key = SDLK_WORLD_3 ,
00288 International4Key = SDLK_WORLD_4 ,
00289 International5Key = SDLK_WORLD_5 ,
00290 International6Key = SDLK_WORLD_6 ,
00291 International7Key = SDLK_WORLD_7 ,
00292 International8Key = SDLK_WORLD_8 ,
00293 International9Key = SDLK_WORLD_9 ,
00294
00295 International10Key = SDLK_WORLD_10 ,
00296 International11Key = SDLK_WORLD_11 ,
00297 International12Key = SDLK_WORLD_12 ,
00298 International13Key = SDLK_WORLD_13 ,
00299 International14Key = SDLK_WORLD_14 ,
00300 International15Key = SDLK_WORLD_15 ,
00301 International16Key = SDLK_WORLD_16 ,
00302 International17Key = SDLK_WORLD_17 ,
00303 International18Key = SDLK_WORLD_18 ,
00304 International19Key = SDLK_WORLD_19 ,
00305
00306 International20Key = SDLK_WORLD_20 ,
00307 International21Key = SDLK_WORLD_21 ,
00308 International22Key = SDLK_WORLD_22 ,
00309 International23Key = SDLK_WORLD_23 ,
00310 International24Key = SDLK_WORLD_24 ,
00311 International25Key = SDLK_WORLD_25 ,
00312 International26Key = SDLK_WORLD_26 ,
00313 International27Key = SDLK_WORLD_27 ,
00314 International28Key = SDLK_WORLD_28 ,
00315 International29Key = SDLK_WORLD_29 ,
00316
00317 International30Key = SDLK_WORLD_30 ,
00318 International31Key = SDLK_WORLD_31 ,
00319 International32Key = SDLK_WORLD_32 ,
00320 International33Key = SDLK_WORLD_33 ,
00321 International34Key = SDLK_WORLD_34 ,
00322 International35Key = SDLK_WORLD_35 ,
00323 International36Key = SDLK_WORLD_36 ,
00324 International37Key = SDLK_WORLD_37 ,
00325 International38Key = SDLK_WORLD_38 ,
00326 International39Key = SDLK_WORLD_39 ,
00327
00328 International40Key = SDLK_WORLD_40 ,
00329 International41Key = SDLK_WORLD_41 ,
00330 International42Key = SDLK_WORLD_42 ,
00331 International43Key = SDLK_WORLD_43 ,
00332 International44Key = SDLK_WORLD_44 ,
00333 International45Key = SDLK_WORLD_45 ,
00334 International46Key = SDLK_WORLD_46 ,
00335 International47Key = SDLK_WORLD_47 ,
00336 International48Key = SDLK_WORLD_48 ,
00337 International49Key = SDLK_WORLD_49 ,
00338
00339 International50Key = SDLK_WORLD_50 ,
00340 International51Key = SDLK_WORLD_51 ,
00341 International52Key = SDLK_WORLD_52 ,
00342 International53Key = SDLK_WORLD_53 ,
00343 International54Key = SDLK_WORLD_54 ,
00344 International55Key = SDLK_WORLD_55 ,
00345 International56Key = SDLK_WORLD_56 ,
00346 International57Key = SDLK_WORLD_57 ,
00347 International58Key = SDLK_WORLD_58 ,
00348 International59Key = SDLK_WORLD_59 ,
00349
00350 International60Key = SDLK_WORLD_60 ,
00351 International61Key = SDLK_WORLD_61 ,
00352 International62Key = SDLK_WORLD_62 ,
00353 International63Key = SDLK_WORLD_63 ,
00354 International64Key = SDLK_WORLD_64 ,
00355 International65Key = SDLK_WORLD_65 ,
00356 International66Key = SDLK_WORLD_66 ,
00357 International67Key = SDLK_WORLD_67 ,
00358 International68Key = SDLK_WORLD_68 ,
00359 International69Key = SDLK_WORLD_69 ,
00360
00361 International70Key = SDLK_WORLD_70 ,
00362 International71Key = SDLK_WORLD_71 ,
00363 International72Key = SDLK_WORLD_72 ,
00364 International73Key = SDLK_WORLD_73 ,
00365 International74Key = SDLK_WORLD_74 ,
00366 International75Key = SDLK_WORLD_75 ,
00367 International76Key = SDLK_WORLD_76 ,
00368 International77Key = SDLK_WORLD_77 ,
00369 International78Key = SDLK_WORLD_78 ,
00370 International79Key = SDLK_WORLD_79 ,
00371
00372 International80Key = SDLK_WORLD_80 ,
00373 International81Key = SDLK_WORLD_81 ,
00374 International82Key = SDLK_WORLD_82 ,
00375 International83Key = SDLK_WORLD_83 ,
00376 International84Key = SDLK_WORLD_84 ,
00377 International85Key = SDLK_WORLD_85 ,
00378 International86Key = SDLK_WORLD_86 ,
00379 International87Key = SDLK_WORLD_87 ,
00380 International88Key = SDLK_WORLD_88 ,
00381 International89Key = SDLK_WORLD_89 ,
00382
00383 International90Key = SDLK_WORLD_90 ,
00384 International91Key = SDLK_WORLD_91 ,
00385 International92Key = SDLK_WORLD_92 ,
00386 International93Key = SDLK_WORLD_93 ,
00387 International94Key = SDLK_WORLD_94 ,
00388 International95Key = SDLK_WORLD_95 ,
00389
00390
00391
00392
00393
00394 ZeroKeypadKey = SDLK_KP0 ,
00395 OneKeypadKey = SDLK_KP1 ,
00396 TwoKeypadKey = SDLK_KP2 ,
00397 ThreeKeypadKey = SDLK_KP3 ,
00398 FourKeypadKey = SDLK_KP4 ,
00399 FiveKeypadKey = SDLK_KP5 ,
00400 SixKeypadKey = SDLK_KP6 ,
00401 SevenKeypadKey = SDLK_KP7 ,
00402 HeightKeypadKey = SDLK_KP8 ,
00403 NineKeypadKey = SDLK_KP9 ,
00404
00405
00406
00407 PeriodKeypadKey = SDLK_KP_PERIOD ,
00408 DivideKeypadKey = SDLK_KP_DIVIDE ,
00409 MultiplyKeypadKey = SDLK_KP_MULTIPLY ,
00410 MinusKeypadKey = SDLK_KP_MINUS ,
00411 PlusKeypadKey = SDLK_KP_PLUS ,
00412
00413
00414 EnterKeypadKey = SDLK_KP_ENTER ,
00415 EqualsKeypadKey = SDLK_KP_EQUALS ,
00416
00417
00418
00419 UpArrowKey = SDLK_UP ,
00420 DownArrowKey = SDLK_DOWN ,
00421 LeftArrowKey = SDLK_LEFT ,
00422 RightArrowKey = SDLK_RIGHT ,
00423 InsertKey = SDLK_INSERT ,
00424 HomeKey = SDLK_HOME ,
00425 EndKey = SDLK_END ,
00426 PageUpKey = SDLK_PAGEUP ,
00427 PageDownKey = SDLK_PAGEDOWN ,
00428
00429
00430
00431 F1Key = SDLK_F1 ,
00432 F2Key = SDLK_F2 ,
00433 F3Key = SDLK_F3 ,
00434 F4Key = SDLK_F4 ,
00435 F5Key = SDLK_F5 ,
00436 F6Key = SDLK_F6 ,
00437 F7Key = SDLK_F7 ,
00438 F8Key = SDLK_F8 ,
00439 F9Key = SDLK_F9 ,
00440 F10Key = SDLK_F10 ,
00441 F11Key = SDLK_F11 ,
00442 F12Key = SDLK_F12 ,
00443 F13Key = SDLK_F13 ,
00444 F14Key = SDLK_F14 ,
00445 F15Key = SDLK_F15 ,
00446
00447
00448
00449 NumLockKey = SDLK_NUMLOCK ,
00450 CapsLockKey = SDLK_CAPSLOCK ,
00451 ScrolLockKey = SDLK_SCROLLOCK ,
00452 LeftShiftKey = SDLK_LSHIFT ,
00453 RightShiftKey = SDLK_RSHIFT ,
00454 LeftControlKey = SDLK_LCTRL ,
00455 RightControlKey = SDLK_RCTRL ,
00456 LeftAltKey = SDLK_LALT ,
00457 RightAltKey = SDLK_RALT ,
00458 LeftMetaKey = SDLK_LMETA ,
00459 RightMetaKey = SDLK_RMETA ,
00460
00461
00462 LeftSuperKey = SDLK_LSUPER ,
00463
00464
00465 RightSuperKey = SDLK_RSUPER ,
00466 ModeKey = SDLK_MODE ,
00467
00468
00469 ComposeKey = SDLK_COMPOSE ,
00470
00471
00472
00473 HelpKey = SDLK_HELP ,
00474 PrintKey = SDLK_PRINT ,
00475 SysReqKey = SDLK_SYSREQ ,
00476 BreakKey = SDLK_BREAK ,
00477 MenuKey = SDLK_MENU ,
00478
00479
00480 PowerKey = SDLK_POWER ,
00481
00482
00483 EuroKey = SDLK_EURO ,
00484
00485
00486 UndoKey = SDLK_UNDO
00487
00488
00489
00490
00491
00492 #else // OSDL_USES_SDL
00493
00494 #if defined(OSDL_ARCH_NINTENDO_DS) && OSDL_ARCH_NINTENDO_DS
00495
00496 #if defined(OSDL_RUNS_ON_ARM9) && OSDL_RUNS_ON_ARM9
00497
00498
00499 ButtonX = KEY_X ,
00500 ButtonY = KEY_Y ,
00501
00502 ButtonA = KEY_A ,
00503 ButtonB = KEY_B ,
00504
00505 ButtonStart = KEY_START ,
00506 ButtonSelect = KEY_SELECT ,
00507
00508 ButtonLeft = KEY_LEFT ,
00509 ButtonRight = KEY_RIGHT ,
00510
00511 ButtonUp = KEY_UP ,
00512 ButtonDown = KEY_DOWN ,
00513
00514 ShoulderButtonLeft = KEY_L ,
00515 ShoulderButtonRight = KEY_R ,
00516
00517 StylusContact = KEY_TOUCH ,
00518 LidOpen = KEY_LID
00519
00520 #endif // defined(OSDL_RUNS_ON_ARM9) && OSDL_RUNS_ON_ARM9
00521
00522 #endif // defined(OSDL_ARCH_NINTENDO_DS) && OSDL_ARCH_NINTENDO_DS
00523
00524 #endif // OSDL_USES_SDL
00525
00526
00527 } ;
00528
00529
00530
00531
00543 enum KeyModifier
00544 {
00545
00546
00547 #if ! defined(OSDL_USES_SDL) || OSDL_USES_SDL
00548
00549 NoneModifier = KMOD_NONE ,
00550
00551 LeftShiftModifier = KMOD_LSHIFT ,
00552 RightShiftModifier = KMOD_RSHIFT ,
00553
00554 LeftControlModifier = KMOD_LCTRL ,
00555 RightControlModifier = KMOD_RCTRL ,
00556
00557 LeftAltModifier = KMOD_LALT ,
00558 RightAltModifier = KMOD_RALT ,
00559
00560 LeftMetaModifier = KMOD_LMETA ,
00561 RightMetaModifier = KMOD_RMETA ,
00562
00563 NumModifier = KMOD_NUM ,
00564 CapsModifier = KMOD_CAPS ,
00565 ModeModifier = KMOD_MODE ,
00566 ReservedModifier = KMOD_RESERVED ,
00567
00568
00569
00570
00571
00572
00573
00574 ShiftModifier = LeftShiftModifier
00575 | RightShiftModifier,
00576
00577 ControlModifier = LeftControlModifier
00578 | RightControlModifier,
00579
00580 AltModifier = LeftAltModifier
00581 | RightAltModifier,
00582
00583 MetaModifier = LeftMetaModifier
00584 | RightMetaModifier
00585
00586 #endif // OSDL_USES_SDL
00587
00588
00589 } ;
00590
00591
00592
00593
00594
00613 explicit KeyboardHandler( KeyboardMode initialMode = rawInput,
00614 bool useSmarterDefaultKeyHandler = false ) ;
00615
00616
00617
00622 virtual ~KeyboardHandler() throw() ;
00623
00624
00625
00644 virtual void linkToController( KeyIdentifier rawKey,
00645 OSDL::MVC::Controller & controller ) ;
00646
00647
00648
00659 virtual void unlinkFromController( KeyIdentifier rawKey,
00660 OSDL::MVC::Controller & controller ) ;
00661
00662
00663
00682 virtual void linkToController( Ceylan::Unicode unicode,
00683 OSDL::MVC::Controller & controller ) ;
00684
00685
00686
00701 virtual void linkToFocusController(
00702 OSDL::MVC::Controller & controller ) ;
00703
00704
00705
00718 virtual void linkToHandler( KeyIdentifier rawKey,
00719 KeyboardEventHandler handler ) ;
00720
00721
00722
00735 virtual void linkToHandler( Ceylan::Unicode unicode,
00736 KeyboardEventHandler handler ) ;
00737
00738
00739
00751 virtual void setSmarterDefaultKeyHandlers() ;
00752
00753
00754
00765 virtual void linkDefaultRawKeyController(
00766 OSDL::MVC::Controller & newDefaultController ) ;
00767
00768
00769
00776 virtual bool unlinkDefaultRawKeyController() ;
00777
00778
00779
00786 virtual void setDefaultRawKeyHandler(
00787 KeyboardEventHandler newHandler ) ;
00788
00789
00790
00797 virtual void setDefaultUnicodeHandler(
00798 KeyboardEventHandler newHandler ) ;
00799
00800
00801
00813 virtual const std::string toString(
00814 Ceylan::VerbosityLevels level = Ceylan::high ) const ;
00815
00816
00817
00818
00819
00820
00821
00822
00834 static KeyboardMode GetMode() ;
00835
00836
00837
00847 static void SetMode( KeyboardMode newMode ) ;
00848
00849
00850
00857 static std::string DescribeKey( KeyIdentifier key ) ;
00858
00859
00860
00868 static std::string DescribeModifier( KeyModifier modifier ) ;
00869
00870
00871
00878 static std::string DescribeUnicode( Ceylan::Unicode value ) ;
00879
00880
00881
00887 static const Ceylan::System::Millisecond
00888 DefaultDelayBeforeKeyRepeat ;
00889
00890
00891
00899 static const Ceylan::System::Millisecond
00900 DefaulKeyRepeatInterval ;
00901
00902
00903
00904
00905
00906 protected:
00907
00908
00909
00917 virtual void focusGained(
00918 const FocusEvent & keyboardFocusEvent ) ;
00919
00920
00921
00929 virtual void focusLost(
00930 const FocusEvent & keyboardFocusEvent ) ;
00931
00932
00933
00949 virtual void keyPressed( const KeyboardEvent & keyboardEvent ) ;
00950
00951
00952
00968 virtual void keyReleased( const KeyboardEvent & keyboardEvent );
00969
00970
00971
00973 static KeyboardMode _CurrentMode ;
00974
00975
00976
00977
00978
00979
00980
00981
00982
00983 #pragma warning( push )
00984 #pragma warning( disable: 4251 )
00985
00986
00997 std::map<KeyIdentifier, OSDL::MVC::Controller *>
00998 _rawKeyControllerMap ;
00999
01000
01001
01020 std::map<KeyIdentifier, KeyboardEventHandler>
01021 _rawKeyHandlerMap ;
01022
01023
01024
01038 std::map<Ceylan::Unicode, OSDL::MVC::Controller *>
01039 _unicodeControllerMap ;
01040
01041
01042
01064 std::map<Ceylan::Unicode, KeyboardEventHandler>
01065 _unicodeHandlerMap ;
01066
01067
01068
01069 #pragma warning( pop )
01070
01071
01072
01073
01078 OSDL::MVC::Controller * _defaultRawKeyController ;
01079
01080
01081
01089 KeyboardEventHandler _defaultRawKeyHandler ;
01090
01091
01092
01100 KeyboardEventHandler _defaultUnicodeHandler ;
01101
01102
01103
01110 OSDL::MVC::Controller * _focusController ;
01111
01112
01113
01119 bool _unicodeInputWasActivated ;
01120
01121
01122
01123
01124 private:
01125
01126
01127
01136 explicit KeyboardHandler( const KeyboardHandler & source ) ;
01137
01138
01139
01148 KeyboardHandler & operator = ( const KeyboardHandler & source );
01149
01150
01151 } ;
01152
01153
01154 }
01155
01156 }
01157
01158
01159
01160 #endif // OSDL_KEYBOARD_HANDLER_H_
01161