#include "maruskin_keymap.h"
+/* keep it consistent with java virtual keycode */
+#define JAVA_KEYCODE_BIT (1 << 24)
+#define JAVA_KEYCODE_BIT_CTRL (1 << 18)
+#define JAVA_KEYCODE_BIT_SHIFT (1 << 17)
+#define JAVA_KEYCODE_BIT_ALT (1 << 16)
+
+#define JAVA_KEY_MASK 0xFFFF;
+
+enum JAVA_KEYCODE {
+ JAVA_KEY_ARROW_UP = 1,
+ JAVA_KEY_ARROW_DOWN,
+ JAVA_KEY_ARROW_LEFT,
+ JAVA_KEY_ARROW_RIGHT,
+ JAVA_KEY_PAGE_UP,
+ JAVA_KEY_PAGE_DOWN,
+ JAVA_KEY_HOME,
+ JAVA_KEY_END,
+ JAVA_KEY_INSERT,
+ JAVA_KEY_F1 = 10,
+ JAVA_KEY_F20 = 29,
+};
+
+
int javakeycode_to_scancode(int java_keycode)
{
-#ifdef _WIN32
- //TODO:
-#endif
- return curses2keycode[java_keycode];
+ int vk = java_keycode & JAVA_KEY_MASK;
+
+/*#ifdef _WIN32
+ return MapVirtualKey(vk, MAPVK_VK_TO_VSC);
+#endif*/
+
+ if (java_keycode & JAVA_KEYCODE_BIT) {
+ if (vk >= JAVA_KEY_F1 && vk <=JAVA_KEY_F20) { //function keys
+ vk += 255;
+ } else { //special keys
+ switch(vk) {
+ case JAVA_KEY_ARROW_UP :
+ vk = KEY_UP;
+ break;
+ case JAVA_KEY_ARROW_DOWN :
+ vk = KEY_DOWN;
+ break;
+ case JAVA_KEY_ARROW_LEFT :
+ vk = KEY_LEFT;
+ break;
+ case JAVA_KEY_ARROW_RIGHT :
+ vk = KEY_RIGHT;
+ break;
+ case JAVA_KEY_PAGE_UP :
+ vk = KEY_PPAGE;
+ break;
+ case JAVA_KEY_PAGE_DOWN :
+ vk = KEY_NPAGE;
+ break;
+ case JAVA_KEY_HOME :
+ vk = KEY_HOME;
+ break;
+ case JAVA_KEY_END :
+ vk = KEY_END;
+ break;
+ case JAVA_KEY_INSERT :
+ vk = KEY_IC;
+ break;
+ default :
+ break;
+ }
+ }
+ //TODO:
+ //meta keys
+ }
+
+ return vkkey2scancode[vk];
}
#define CNTRL_CODE 0x1d
#define CNTRL SCANCODE_CTRL*/
-#define CURSES_KEYS 0777
-//KEY_MAX /* KEY_MAX defined in <curses.h> */
+#define KEY_MAX 0777
-static const int curses2keycode[CURSES_KEYS] = {
- [0 ... (CURSES_KEYS - 1)] = -1,
+#define KEY_F0 0410
+#define KEY_F(n) (KEY_F0+(n))
+
+#define GREY 0x80
+#define SHIFT 0x100
+#define KEY_ESCAPE 0x01b
+
+#define KEY_DOWN 0402
+#define KEY_UP 0403
+#define KEY_LEFT 0404
+#define KEY_RIGHT 0405
+#define KEY_HOME 0406
+
+#define KEY_DC 0512
+#define KEY_IC 0513
+#define KEY_NPAGE 0522
+#define KEY_PPAGE 0523
+#define KEY_ENTER 0527
+#define KEY_END 0550
+
+
+
+static const int vkkey2scancode[KEY_MAX] = {
+ [0 ... (KEY_MAX - 1)] = -1,
[0x01b] = 1, /* Escape */
['1'] = 2,
[']'] = 27,
['\n'] = 28, /* Return */
['\r'] = 28, /* Return */
- //[KEY_ENTER] = 28, /* Return */
+ [KEY_ENTER] = 28, /* Return */
['a'] = 30,
['s'] = 31,
[' '] = 57,
-#if 0
[KEY_F(1)] = 59, /* Function Key 1 */
[KEY_F(2)] = 60, /* Function Key 2 */
[KEY_F(3)] = 61, /* Function Key 3 */
[KEY_F(11)] = 87, /* Function Key 11 */
[KEY_F(12)] = 88, /* Function Key 12 */
- [KEY_HOME] = 71 | GREY, /* Home */
- [KEY_UP] = 72 | GREY, /* Up Arrow */
- [KEY_PPAGE] = 73 | GREY, /* Page Up */
- [KEY_LEFT] = 75 | GREY, /* Left Arrow */
- [KEY_RIGHT] = 77 | GREY, /* Right Arrow */
- [KEY_END] = 79 | GREY, /* End */
- [KEY_DOWN] = 80 | GREY, /* Down Arrow */
- [KEY_NPAGE] = 81 | GREY, /* Page Down */
- [KEY_IC] = 82 | GREY, /* Insert */
- [KEY_DC] = 83 | GREY, /* Delete */
+ [KEY_HOME] = 71, /* Home */
+ [KEY_UP] = 72, /* Up Arrow */
+ [KEY_PPAGE] = 73, /* Page Up */
+ [KEY_LEFT] = 75, /* Left Arrow */
+ [KEY_RIGHT] = 77, /* Right Arrow */
+ [KEY_END] = 79, /* End */
+ [KEY_DOWN] = 80, /* Down Arrow */
+ [KEY_NPAGE] = 81, /* Page Down */
+ [KEY_IC] = 82, /* Insert */
+ [KEY_DC] = 83, /* Delete */
+#if 0
['!'] = 2 | SHIFT,
['@'] = 3 | SHIFT,
['#'] = 4 | SHIFT,