input: allow to map key/button to enter and escape keys.

This commit is contained in:
sorgelig
2019-04-11 00:55:15 +08:00
parent 92f20ce7cf
commit 9740549327
2 changed files with 32 additions and 29 deletions

View File

@@ -1142,7 +1142,6 @@ static int mapping_button;
static int mapping_dev;
static int mapping_type;
static int mapping_count;
static uint8_t mapping_key;
static uint32_t tmp_axis[4];
static int tmp_axis_n = 0;
@@ -1162,7 +1161,7 @@ void start_map_setting(int cnt)
int get_map_button()
{
return (mapping_type == 2) ? mapping_key : mapping_button;
return mapping_button;
}
int get_map_type()
@@ -1556,7 +1555,7 @@ static void input_cb(struct input_event *ev, struct input_absinfo *absinfo, int
}
//mapping
if (mapping && (mapping_dev >=0 || ev->value) && !cancel && !enter)
if (mapping && (mapping_dev >=0 || ev->value) && !((mapping_type < 2 || !mapping_button) && (cancel || enter)))
{
if (is_menu_core()) spi_uio_cmd(UIO_KEYBOARD); //ping the Menu core to wakeup
@@ -1564,40 +1563,43 @@ static void input_cb(struct input_event *ev, struct input_absinfo *absinfo, int
{
if (mapping_type == 2)
{
if (ev->value == 1 && ev->code < 256)
if (ev->code < 256)
{
if(mapping_dev < 0)
if (ev->value == 1)
{
mapping_dev = dev;
mapping_key = 0;
if (mapping_dev < 0)
{
mapping_dev = dev;
mapping_button = 0;
}
if (!mapping_button) mapping_button = ev->code;
}
if (!mapping_key) mapping_key = ev->code;
else
if (ev->value == 0 && mapping_dev >= 0 && mapping_button && mapping_button != ev->code)
{
input[mapping_dev].kbdmap[mapping_key] = ev->code;
mapping_key = 0;
input[mapping_dev].kbdmap[mapping_button] = ev->code;
mapping_button = 0;
}
}
return;
}
else if (mapping_type == 3)
{
if (ev->value == 1)
if (ev->value == 1 && !mapping_button)
{
if (!mapping_button)
{
if (mapping_dev < 0) mapping_dev = dev;
if (mapping_dev == dev && ev->code < 1024) mapping_button = ev->code;
}
else if (mapping_dev >= 0 && (ev->code<256 || mapping_dev == dev))
{
// Technically it's hard to map the key to button as keyboards
// are all the same while joysticks are personalized and numbered.
input[mapping_dev].jkmap[mapping_button] = ev->code;
mapping_button = 0;
}
if (mapping_dev < 0) mapping_dev = dev;
if (mapping_dev == dev && ev->code < 1024) mapping_button = ev->code;
}
if (ev->value == 0 && mapping_dev >= 0 && (ev->code<256 || mapping_dev == dev) && mapping_button && mapping_button != ev->code)
{
// Technically it's hard to map the key to button as keyboards
// are all the same while joysticks are personalized and numbered.
input[mapping_dev].jkmap[mapping_button] = ev->code;
mapping_button = 0;
}
return;
}
else if ((mapping_dev < 0) || ((ev->code >= 256) ? mapping_type : !mapping_type))
{
@@ -1628,7 +1630,6 @@ static void input_cb(struct input_event *ev, struct input_absinfo *absinfo, int
key_mapped = 0;
}
}
return;
}
}
@@ -2026,6 +2027,7 @@ static void input_cb(struct input_event *ev, struct input_absinfo *absinfo, int
}
}
if (code == KEY_HOMEPAGE) code = KEY_MENU;
user_io_kbd(code, ev->value);
return;
}

View File

@@ -1886,6 +1886,7 @@ void HandleUI(void)
sprintf(s, " on device %04x:%04x", get_map_vid(), get_map_pid());
OsdWrite(3, s, 0, 0);
}
OsdWrite(OsdGetSize() - 1, " Enter \x16 Finish, Esc \x16 Clear", menusub == 0, 0);
}
else
{
@@ -1901,7 +1902,7 @@ void HandleUI(void)
OsdWrite(2, " on the same pad", 0, 0);
OsdWrite(3, " or key on a keyboard", 0, 0);
}
OsdWrite(OsdGetSize() - 1, " Enter \x16 Finish, Esc \x16 Clear", menusub == 0, 0);
OsdWrite(OsdGetSize() - 1);
}
if (select || menu)
@@ -3595,17 +3596,17 @@ void HandleUI(void)
sprintf(s, " on keyboard %04x:%04x", get_map_vid(), get_map_pid());
}
OsdWrite(5, s, 0, 0);
OsdWrite(OsdGetSize() - 1, " finish", menusub == 0, 0);
}
else
{
flag = 1;
sprintf(s, " Press key to map %02X to", get_map_button() & 0xFF);
sprintf(s, " Press key to map 0x%02X to", get_map_button() & 0xFF);
OsdWrite(3, s, 0, 0);
OsdWrite(5, " on any keyboard", 0, 0);
OsdWrite(OsdGetSize() - 1);
}
OsdWrite(OsdGetSize() - 1, " finish", menusub == 0, 0);
if (select || menu)
{
finish_map_setting(menu);