Input mapping is now completely macroed.

This commit is contained in:
Merlijn Wajer 2012-12-04 19:57:30 +01:00
parent 36ad37749c
commit 81ad877ce2
2 changed files with 43 additions and 32 deletions

39
custom_map.h Normal file
View File

@ -0,0 +1,39 @@
#define KEYMAP(in_key, out_key, out_type, device, val) \
case in_key: \
je.type = out_type; \
je.code = out_key; \
je.value = val(e.value); \
j = device; \
break;
/* First joystick */
/* HAT */
KEYMAP(KEY_UP, ABS_HAT0Y, EV_ABS, 0, -)
KEYMAP(KEY_DOWN, ABS_HAT0Y, EV_ABS, 0, )
KEYMAP(KEY_LEFT, ABS_HAT0X, EV_ABS, 0, -)
KEYMAP(KEY_RIGHT, ABS_HAT0X, EV_ABS, 0, )
/* Red buttons */
KEYMAP(KEY_LEFTCTRL, BTN_0, EV_KEY, 0, )
KEYMAP(KEY_LEFTALT, BTN_1, EV_KEY, 0, )
KEYMAP(KEY_SPACE, BTN_2, EV_KEY, 0, )
/* Yellow button */
KEYMAP(KEY_1, BTN_3, EV_KEY, 0, )
/* Second joystick */
/* HAT*/
KEYMAP(KEY_R, ABS_HAT0Y, EV_ABS, 1, -)
KEYMAP(KEY_F, ABS_HAT0Y, EV_ABS, 1, )
KEYMAP(KEY_D, ABS_HAT0X, EV_ABS, 1, -)
KEYMAP(KEY_G, ABS_HAT0X, EV_ABS, 1, )
/* Red buttons */
KEYMAP(KEY_A, BTN_0, EV_KEY, 1, )
KEYMAP(KEY_S, BTN_1, EV_KEY, 1, )
KEYMAP(KEY_Q, BTN_2, EV_KEY, 1, )
/* Yellow button */
KEYMAP(KEY_2, BTN_3, EV_KEY, 1,)

36
map.c
View File

@ -176,41 +176,13 @@ int main(int argc, char** argv) {
nowrite = 0;
j = 0;
/* Only catch keys and ignore auto-repeat (value == 2) */
if (e.type == EV_KEY && e.value != 2) {
switch(e.code) {
case KEY_UP:
je.type = EV_ABS; je.code = ABS_HAT0Y; je.value = -e.value; j = 0; break;
case KEY_DOWN:
je.type = EV_ABS; je.code = ABS_HAT0Y; je.value = e.value; j = 0; break;
case KEY_LEFT:
je.type = EV_ABS; je.code = ABS_HAT0X; je.value = -e.value; j = 0; break;
case KEY_RIGHT:
je.type = EV_ABS; je.code = ABS_HAT0X; je.value = e.value; j = 0; break;
case KEY_LEFTCTRL:
je.type = EV_KEY; je.code = BTN_0; je.value = e.value; j = 0; break;
case KEY_LEFTALT:
je.type = EV_KEY; je.code = BTN_1; je.value = e.value; j = 0; break;
case KEY_SPACE:
je.type = EV_KEY; je.code = BTN_2; je.value = e.value; j = 0; break;
case KEY_1:
je.type = EV_KEY; je.code = BTN_3; je.value = e.value; j = 0; break;
case KEY_R:
je.type = EV_ABS; je.code = ABS_HAT0Y; je.value = -e.value; j = 1; break;
case KEY_F:
je.type = EV_ABS; je.code = ABS_HAT0Y; je.value = e.value; j = 1; break;
case KEY_D:
je.type = EV_ABS; je.code = ABS_HAT0X; je.value = -e.value; j = 1; break;
case KEY_G:
je.type = EV_ABS; je.code = ABS_HAT0X; je.value = e.value; j = 1; break;
case KEY_A:
je.type = EV_KEY; je.code = BTN_0; je.value = e.value; j = 1; break;
case KEY_S:
je.type = EV_KEY; je.code = BTN_1; je.value = e.value; j = 1; break;
case KEY_Q:
je.type = EV_KEY; je.code = BTN_2; je.value = e.value; j = 1; break;
case KEY_2:
je.type = EV_KEY; je.code = BTN_3; je.value = e.value; j = 1; break;
#include "custom_map.h"
default:
nowrite = 1;
}