Skip to content
Browse files

add keyboard us layout

 add mtk_config_set_keyboard_layout
  • Loading branch information...
1 parent ba42bfd commit b4999fe7a64eb71e422777dbeb52c348681835a1 Xiangfu Liu committed
Showing with 46 additions and 6 deletions.
  1. +7 −0 include/mtklib.h
  2. +39 −6 lib/keymap.c
View
7 include/mtklib.h
@@ -199,4 +199,11 @@ extern char mtk_get_ascii(int app_id, int keycode);
extern void mtk_config_set_wallpaper(unsigned short *wallpaper_bitmap, unsigned int wallpaper_w, unsigned int wallpaper_h);
+enum {
+ MTK_KEYBOARD_LAYOUT_US = 0,
+ MTK_KEYBOARD_LAYOUT_FRENCH,
+ MTK_KEYBOARD_LAYOUT_GERMAN
+};
+extern void mtk_config_set_keyboard_layout(int layout);
+
#endif /* __MTK_INCLUDE_MTKLIB_H_ */
View
45 lib/keymap.c
@@ -27,21 +27,46 @@
#define PAR 167 /* '§' */
#define DEG 176 /* '°' */
-static char keymap[128] = {
- 0,ESC,'1','2','3','4','5','6','7','8','9','0','-', '=', BS,TAB,
+static int curr_layout = 2;
+
+/*TODO: ` - \ those three chars not working in US layout
+ add french layout */
+
+static char keymap[3][128] = {
+ { 0,ESC,'1','2','3','4','5','6','7','8','9','0', 0, 0, BS,TAB, /* 16 */
+ 'q','w','e','r','t','y','u','i','o','p','[',']', LF, 0,'a','s', /* 32 */
+ 'd','f','g','h','j','k','l',';','\'', 0, 0,'=','z','x','c','v', /* 48 */
+ 'b','n','m',',','.','/', 0,'*', 0,' ', 0, 0, 0, 0, 0, 0, /* 64 */
+ 0, 0, 0, 0, 0, 0, 0,'7','8','9','-','4','5','6','+','1', /* 80 */
+ '2','3','0','.', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 96 */
+ LF, 0,'/', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 112 */
+ }, /* US layout */
+ {0
+ }, /* French layout */
+ { 0,ESC,'1','2','3','4','5','6','7','8','9','0','-', '=',BS,TAB,
'q','w','e','r','t','z','u','i','o','p', UE,'+', LF, 0,'a','s',
'd','f','g','h','j','k','l',OE, AE,'^', 0,'#','y','x','c','v',
'b','n','m',',','.','-', 0,'*', 0,' ', 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0,'7','8','9','-','4','5','6','+','1',
'2','3','0',',', 0, 0,'<', 0, 0, 0, 0, 0, 0, 0, 0, 0,
LF, 0,'/', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ } /* German layout */
};
-static char shift[128] = {
- ' ', 0 , 0 , 39, 0 , 0 , 0 , 0 , 0 , 0 , 0 ,'*',';','_',':', 0 ,
+static char shift[3][128] = {
+ {' ', 0 , 0 , 0 , 0 , 0 , 0,'\"', 0 , 0 , 0 , 0 ,'<','_','>','?', /* 16 */
+ ')','!','@','#','$','%','^','&','*','(', 0 ,':', 0 ,'+', 0 , 0 , /* 32 */
+ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , /* 48 */
+ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,'{','|','}', 0 , 0 , /* 64 */
+ '~',
+ }, /* US layout */
+ {0
+ }, /* French layout */
+ {' ', 0 , 0 , 39, 0 , 0 , 0 , 0 , 0 , 0 , 0 ,'*',';','_',':', 0 ,
'=','!','"',PAR,'$','%','&','/','(',')', 0 , 0 ,'>', 0 , 0 , 0 ,
0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,DEG, 0 ,
+ } /* German layout */
};
int init_keymap(struct mtk_services *d);
@@ -55,7 +80,7 @@ static char get_ascii(int keycode,int switches)
{
char result;
if (keycode>=112) return 0;
- result = keymap[keycode];
+ result = keymap[curr_layout][keycode];
if (!result) return 0;
if (switches & (KEYMAP_SWITCH_LSHIFT|KEYMAP_SWITCH_RSHIFT)) {
if ((result >= 'a') && (result <= 'z')) {
@@ -63,7 +88,7 @@ static char get_ascii(int keycode,int switches)
return result;
}
result-=32;
- if (result<64) return shift[(s32)result];
+ if (result<64) return shift[curr_layout][(s32)result];
}
return result;
}
@@ -86,3 +111,11 @@ int init_keymap(struct mtk_services *d)
d->register_module("Keymap 1.0",&services);
return 1;
}
+
+void mtk_config_set_keyboard_layout(int layout)
+{
+ if (curr_layout < 0 || curr_layout > 2)
+ return;
+
+ curr_layout = layout;
+}

0 comments on commit b4999fe

Please sign in to comment.
Something went wrong with that request. Please try again.