7 #include "SDL_keysym.h"
8 #include "SDL_keyboard.h"
9 #include "SDL_events_c.h"
10 #include "SDL_timer.h"
13 #include "SDL_epocvideo.h"
14 #include "SDL_epocevents_c.h"
15 #include "sdlepocapi.h"
21 static SDL_keysym
*TranslateKey(_THIS
, int scancode
, SDL_keysym
*keysym
);
24 /* The translation tables from a console scancode to a SDL keysym */
25 static SDLKey keymap
[MAX_SCANCODE
];
26 static SDL_keysym
*TranslateKey(_THIS
, int scancode
, SDL_keysym
*keysym
);
37 /* Initialize the key translation table */
38 for ( i
=0; i
<SDL_TABLESIZE(keymap
); ++i
)
39 keymap
[i
] = SDLK_UNKNOWN
;
42 for ( i
= 0; i
<32; ++i
){
43 keymap
[' ' + i
] = (SDLKey
)(SDLK_SPACE
+i
);
45 /* e.g. Alphabet keys */
46 for ( i
= 0; i
<32; ++i
){
47 keymap
['A' + i
] = (SDLKey
)(SDLK_a
+i
);
50 keymap
[EStdKeyBackspace
] = SDLK_BACKSPACE
;
51 keymap
[EStdKeyTab
] = SDLK_TAB
;
52 keymap
[EStdKeyEnter
] = SDLK_RETURN
;
53 keymap
[EStdKeyEscape
] = SDLK_ESCAPE
;
54 keymap
[EStdKeySpace
] = SDLK_SPACE
;
55 keymap
[EStdKeyPause
] = SDLK_PAUSE
;
56 keymap
[EStdKeyHome
] = SDLK_HOME
;
57 keymap
[EStdKeyEnd
] = SDLK_END
;
58 keymap
[EStdKeyPageUp
] = SDLK_PAGEUP
;
59 keymap
[EStdKeyPageDown
] = SDLK_PAGEDOWN
;
60 keymap
[EStdKeyDelete
] = SDLK_DELETE
;
61 keymap
[EStdKeyUpArrow
] = SDLK_UP
;
62 keymap
[EStdKeyDownArrow
] = SDLK_DOWN
;
63 keymap
[EStdKeyLeftArrow
] = SDLK_LEFT
;
64 keymap
[EStdKeyRightArrow
] = SDLK_RIGHT
;
65 keymap
[EStdKeyCapsLock
] = SDLK_CAPSLOCK
;
66 keymap
[EStdKeyLeftShift
] = SDLK_LSHIFT
;
67 keymap
[EStdKeyRightShift
] = SDLK_RSHIFT
;
68 keymap
[EStdKeyLeftAlt
] = SDLK_LALT
;
69 keymap
[EStdKeyRightAlt
] = SDLK_RALT
;
70 keymap
[EStdKeyLeftCtrl
] = SDLK_LCTRL
;
71 keymap
[EStdKeyRightCtrl
] = SDLK_RCTRL
;
72 keymap
[EStdKeyLeftFunc
] = SDLK_LMETA
;
73 keymap
[EStdKeyRightFunc
] = SDLK_RMETA
;
74 keymap
[EStdKeyInsert
] = SDLK_INSERT
;
75 keymap
[EStdKeyComma
] = SDLK_COMMA
;
76 keymap
[EStdKeyFullStop
] = SDLK_PERIOD
;
77 keymap
[EStdKeyForwardSlash
] = SDLK_SLASH
;
78 keymap
[EStdKeyBackSlash
] = SDLK_BACKSLASH
;
79 keymap
[EStdKeySemiColon
] = SDLK_SEMICOLON
;
80 keymap
[EStdKeySingleQuote
] = SDLK_QUOTE
;
81 keymap
[EStdKeyHash
] = SDLK_HASH
;
82 keymap
[EStdKeySquareBracketLeft
] = SDLK_LEFTBRACKET
;
83 keymap
[EStdKeySquareBracketRight
] = SDLK_RIGHTBRACKET
;
84 keymap
[EStdKeyMinus
] = SDLK_MINUS
;
85 keymap
[EStdKeyEquals
] = SDLK_EQUALS
;
87 keymap
[EStdKeyF1
] = SDLK_F1
;
88 keymap
[EStdKeyF2
] = SDLK_F2
;
89 keymap
[EStdKeyF3
] = SDLK_F3
;
90 keymap
[EStdKeyF4
] = SDLK_F4
;
91 keymap
[EStdKeyF5
] = SDLK_F5
;
92 keymap
[EStdKeyF6
] = SDLK_F6
;
93 keymap
[EStdKeyF7
] = SDLK_F7
;
94 keymap
[EStdKeyF8
] = SDLK_F8
;
96 keymap
[EStdKeyF9
] = SDLK_F9
;
97 keymap
[EStdKeyF10
] = SDLK_F10
;
98 keymap
[EStdKeyF11
] = SDLK_F11
;
99 keymap
[EStdKeyF12
] = SDLK_F12
;
101 keymap
[EStdKeyXXX
] = SDLK_RETURN
; /* "fire" key */
103 keymap
[EStdKeyDevice3
] = SDLK_RETURN
; /* "fire" key */
104 keymap
[EStdKeyNkpAsterisk
] = SDLK_ASTERISK
;
105 keymap
[EStdKeyYes
] = SDLK_HOME
; /* "call" key */
106 keymap
[EStdKeyNo
] = SDLK_END
; /* "end call" key */
107 keymap
[EStdKeyDevice0
] = SDLK_SPACE
; /* right menu key */
108 keymap
[EStdKeyDevice1
] = SDLK_ESCAPE
; /* left menu key */
109 keymap
[EStdKeyDevice2
] = SDLK_POWER
; /* power key */
111 keymap
[EStdKeyMenu
] = SDLK_MENU
; // menu key
112 keymap
[EStdKeyDevice6
] = SDLK_LEFT
; // Rocker (joystick) left
113 keymap
[EStdKeyDevice7
] = SDLK_RIGHT
; // Rocker (joystick) right
114 keymap
[EStdKeyDevice8
] = SDLK_UP
; // Rocker (joystick) up
115 keymap
[EStdKeyDevice9
] = SDLK_DOWN
; // Rocker (joystick) down
116 keymap
[EStdKeyLeftFunc
] = SDLK_LALT
; //chr?
117 keymap
[EStdKeyRightFunc
] = SDLK_RALT
;
118 keymap
[EStdKeyDeviceA
] = SDLK_RETURN
; /* "fire" key */
120 keymap
[EStdKeyNumLock
] = SDLK_NUMLOCK
;
121 keymap
[EStdKeyScrollLock
] = SDLK_SCROLLOCK
;
123 keymap
[EStdKeyNkpForwardSlash
] = SDLK_KP_DIVIDE
;
124 keymap
[EStdKeyNkpAsterisk
] = SDLK_KP_MULTIPLY
;
125 keymap
[EStdKeyNkpMinus
] = SDLK_KP_MINUS
;
126 keymap
[EStdKeyNkpPlus
] = SDLK_KP_PLUS
;
127 keymap
[EStdKeyNkpEnter
] = SDLK_KP_ENTER
;
128 keymap
[EStdKeyNkp1
] = SDLK_KP1
;
129 keymap
[EStdKeyNkp2
] = SDLK_KP2
;
130 keymap
[EStdKeyNkp3
] = SDLK_KP3
;
131 keymap
[EStdKeyNkp4
] = SDLK_KP4
;
132 keymap
[EStdKeyNkp5
] = SDLK_KP5
;
133 keymap
[EStdKeyNkp6
] = SDLK_KP6
;
134 keymap
[EStdKeyNkp7
] = SDLK_KP7
;
135 keymap
[EStdKeyNkp8
] = SDLK_KP8
;
136 keymap
[EStdKeyNkp9
] = SDLK_KP9
;
137 keymap
[EStdKeyNkp0
] = SDLK_KP0
;
138 keymap
[EStdKeyNkpFullStop
] = SDLK_KP_PERIOD
;
140 keymap
[EStdKeyDecVolume
] = SDLK_VOLDOWN
;
141 keymap
[EStdKeyIncVolume
] = SDLK_VOLUP
;
144 int EPOC_HandleWsEvent(_THIS
, const TWsEvent
& aWsEvent
)
149 switch (aWsEvent
.Type())
151 case EEventSwitchOff
:
155 case EEventKeyDown
: /* Key events */
157 posted
+= SDL_PrivateKeyboard(SDL_PRESSED
, TranslateKey(_this
, aWsEvent
.Key()->iScanCode
, &keysym
));
161 case EEventKeyUp
: /* Key events */
163 posted
+= SDL_PrivateKeyboard(SDL_RELEASED
, TranslateKey(_this
, aWsEvent
.Key()->iScanCode
, &keysym
));
167 case EEventFocusGained
: /* SDL window got focus */
169 Private
->iIsWindowFocused
= ETrue
;
170 posted
+= SDL_PrivateAppActive(1, SDL_APPINPUTFOCUS
|SDL_APPMOUSEFOCUS
);
174 case EEventFocusLost
: /* SDL window lost focus */
176 Private
->iIsWindowFocused
= EFalse
;
177 posted
+= SDL_PrivateAppActive(0, SDL_APPINPUTFOCUS
|SDL_APPMOUSEFOCUS
);
181 case EEventModifiersChanged
:
183 TModifiersChangedEvent
* modEvent
= aWsEvent
.ModifiersChanged();
184 TUint modstate
= KMOD_NONE
;
185 if (modEvent
->iModifiers
== EModifierLeftShift
)
186 modstate
|= KMOD_LSHIFT
;
187 if (modEvent
->iModifiers
== EModifierRightShift
)
188 modstate
|= KMOD_RSHIFT
;
189 if (modEvent
->iModifiers
== EModifierLeftCtrl
)
190 modstate
|= KMOD_LCTRL
;
191 if (modEvent
->iModifiers
== EModifierRightCtrl
)
192 modstate
|= KMOD_RCTRL
;
193 if (modEvent
->iModifiers
== EModifierLeftAlt
)
194 modstate
|= KMOD_LALT
;
195 if (modEvent
->iModifiers
== EModifierRightAlt
)
196 modstate
|= KMOD_RALT
;
197 if (modEvent
->iModifiers
== EModifierLeftFunc
)
198 modstate
|= KMOD_LMETA
;
199 if (modEvent
->iModifiers
== EModifierRightFunc
)
200 modstate
|= KMOD_RMETA
;
201 if (modEvent
->iModifiers
== EModifierCapsLock
)
202 modstate
|= KMOD_CAPS
;
203 SDL_SetModState(STATIC_CAST(SDLMod
,(modstate
| KMOD_LSHIFT
)));
207 case EEventScreenDeviceChanged
:
209 EpocSdlEnv::WaitDeviceChange();
222 void EPOC_PumpEvents(_THIS
)
224 MEventQueue
& events
= EpocSdlEnv::EventQueue();
225 while(events
.HasData())
227 const TWsEvent event
= events
.Shift();
228 EPOC_HandleWsEvent(_this
, event
);
232 void EPOC_InitOSKeymap(_THIS
)
235 EpocSdlEnv::ObserverEvent(MSDLObserver::EEventKeyMapInit
,0);
238 static SDL_keysym
*TranslateKey(_THIS
, int scancode
, SDL_keysym
*keysym
)
240 /* Set the keysym information */
242 keysym
->scancode
= scancode
;
244 if ((scancode
>= MAX_SCANCODE
) &&
245 ((scancode
- ENonCharacterKeyBase
+ 0x0081) >= MAX_SCANCODE
)) {
246 SDL_SetError("Too big scancode");
247 keysym
->scancode
= SDLK_UNKNOWN
;
248 keysym
->mod
= KMOD_NONE
;
252 keysym
->mod
= SDL_GetModState();
254 /* Handle function keys: F1, F2, F3 ... */
255 if (keysym
->mod
& KMOD_META
) {
256 if (scancode
>= 'A' && scancode
< ('A' + 24)) { /* first 32 alphabet keys */
258 case 'Q': scancode
= EStdKeyF1
; break;
259 case 'W': scancode
= EStdKeyF2
; break;
260 case 'E': scancode
= EStdKeyF3
; break;
261 case 'R': scancode
= EStdKeyF4
; break;
262 case 'T': scancode
= EStdKeyF5
; break;
263 case 'Y': scancode
= EStdKeyF6
; break;
264 case 'U': scancode
= EStdKeyF7
; break;
265 case 'I': scancode
= EStdKeyF8
; break;
266 case 'A': scancode
= EStdKeyF9
; break;
267 case 'S': scancode
= EStdKeyF10
; break;
268 case 'D': scancode
= EStdKeyF11
; break;
269 case 'F': scancode
= EStdKeyF12
; break;
271 keysym
->sym
= keymap
[scancode
];
275 if (scancode
>= ENonCharacterKeyBase
) {
276 // Non character keys
277 keysym
->sym
= keymap
[scancode
-
278 ENonCharacterKeyBase
+ 0x0081]; // !!hard coded
280 keysym
->sym
= keymap
[scancode
];
283 /* Remap the arrow keys if the device is rotated */
285 if (Private->EPOC_ScreenOrientation == CFbsBitGc::EGraphicsOrientationRotated270) {
286 switch(keysym->sym) {
287 case SDLK_UP: keysym->sym = SDLK_LEFT; break;
288 case SDLK_DOWN: keysym->sym = SDLK_RIGHT; break;
289 case SDLK_LEFT: keysym->sym = SDLK_DOWN; break;
290 case SDLK_RIGHT:keysym->sym = SDLK_UP; break;
294 /* If UNICODE is on, get the UNICODE value for the key */