(WIN32) LED keyboard driver cleanup

This commit is contained in:
sonninnos 2022-06-05 08:26:49 +03:00
parent 9ea46f34fb
commit 38f258c504

View File

@ -5,16 +5,10 @@
#include "../../configuration.h" #include "../../configuration.h"
#include "../../retroarch.h" #include "../../retroarch.h"
#undef MAX_LEDS
#define MAX_LEDS 3
#ifdef _WIN32
#include <windows.h> #include <windows.h>
#endif
static void key_translate(int *key) static void key_translate(int *key)
{ {
#ifdef _WIN32
switch (*key) switch (*key)
{ {
case 0: case 0:
@ -26,8 +20,10 @@ static void key_translate(int *key)
case 2: case 2:
*key = VK_SCROLL; *key = VK_SCROLL;
break; break;
default:
*key = 0;
break;
} }
#endif
} }
typedef struct typedef struct
@ -42,6 +38,17 @@ typedef struct
static keyboard_led_t win32kb_curins; static keyboard_led_t win32kb_curins;
static keyboard_led_t *win32kb_cur = &win32kb_curins; static keyboard_led_t *win32kb_cur = &win32kb_curins;
static int get_led(int key)
{
return GetKeyState(key);
}
static void set_led(int key)
{
keybd_event(key, 0x45, KEYEVENTF_EXTENDEDKEY | 0, 0);
keybd_event(key, 0x45, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0);
}
static int keyboard_led(int led, int state) static int keyboard_led(int led, int state)
{ {
int status; int status;
@ -51,10 +58,10 @@ static int keyboard_led(int led, int state)
return -1; return -1;
key_translate(&key); key_translate(&key);
if (!key)
return -1;
#ifdef _WIN32 status = get_led(key);
status = GetKeyState(key);
#endif
if (state == -1) if (state == -1)
return status; return status;
@ -62,11 +69,8 @@ static int keyboard_led(int led, int state)
if ((state && !status) || if ((state && !status) ||
(!state && status)) (!state && status))
{ {
#ifdef _WIN32 set_led(key);
keybd_event(key, 0x45, KEYEVENTF_EXTENDEDKEY | 0, 0);
keybd_event(key, 0x45, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0);
win32kb_cur->state[led] = state; win32kb_cur->state[led] = state;
#endif
} }
return -1; return -1;
} }