win rawinput: move all GetRawInputData into one
This commit is contained in:
@@ -114,13 +114,13 @@ extern int get_vidpause(void);
|
|||||||
extern void show_cursor(int);
|
extern void show_cursor(int);
|
||||||
|
|
||||||
extern void keyboard_getkeymap(void);
|
extern void keyboard_getkeymap(void);
|
||||||
extern void keyboard_handle(LPARAM lParam, int infocus);
|
extern void keyboard_handle(PRAWINPUT raw);
|
||||||
|
|
||||||
extern void win_mouse_init(void);
|
extern void win_mouse_init(void);
|
||||||
extern void win_mouse_close(void);
|
extern void win_mouse_close(void);
|
||||||
#ifndef USE_DINPUT
|
extern void win_mouse_handle(PRAWINPUT raw);
|
||||||
extern void win_mouse_handle(LPARAM lParam, int infocus);
|
|
||||||
#endif
|
extern void win_joystick_handle(PRAWINPUT raw);
|
||||||
|
|
||||||
extern void win_notify_dlg_open(void);
|
extern void win_notify_dlg_open(void);
|
||||||
extern void win_notify_dlg_closed(void);
|
extern void win_notify_dlg_closed(void);
|
||||||
|
@@ -336,3 +336,4 @@ void joystick_process(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void win_joystick_handle(PRAWINPUT raw) {}
|
||||||
|
@@ -18,7 +18,7 @@
|
|||||||
* Copyright 2016-2018 Miran Grca.
|
* Copyright 2016-2018 Miran Grca.
|
||||||
* Copyright 2019 GH Cao.
|
* Copyright 2019 GH Cao.
|
||||||
*/
|
*/
|
||||||
#include <Xinput.h>
|
#include <xinput.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
@@ -260,3 +260,4 @@ void joystick_process(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void win_joystick_handle(PRAWINPUT raw) {}
|
@@ -108,30 +108,12 @@ keyboard_getkeymap(void)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
keyboard_handle(LPARAM lParam, int infocus)
|
keyboard_handle(PRAWINPUT raw)
|
||||||
{
|
{
|
||||||
uint32_t ri_size = 0;
|
|
||||||
UINT size;
|
|
||||||
RAWINPUT *raw;
|
|
||||||
USHORT scancode;
|
USHORT scancode;
|
||||||
static int recv_lalt = 0, recv_ralt = 0, recv_tab = 0;
|
static int recv_lalt = 0, recv_ralt = 0, recv_tab = 0;
|
||||||
|
|
||||||
if (! infocus) return;
|
RAWKEYBOARD rawKB = raw->data.keyboard;
|
||||||
|
|
||||||
GetRawInputData((HRAWINPUT)lParam, RID_INPUT, NULL,
|
|
||||||
&size, sizeof(RAWINPUTHEADER));
|
|
||||||
|
|
||||||
raw = malloc(size);
|
|
||||||
if (raw == NULL) return;
|
|
||||||
|
|
||||||
/* Here we read the raw input data for the keyboard */
|
|
||||||
ri_size = GetRawInputData((HRAWINPUT)(lParam), RID_INPUT,
|
|
||||||
raw, &size, sizeof(RAWINPUTHEADER));
|
|
||||||
if (ri_size != size) return;
|
|
||||||
|
|
||||||
/* If the input is keyboard, we process it */
|
|
||||||
if (raw->header.dwType == RIM_TYPEKEYBOARD) {
|
|
||||||
RAWKEYBOARD rawKB = raw->data.keyboard;
|
|
||||||
scancode = rawKB.MakeCode;
|
scancode = rawKB.MakeCode;
|
||||||
|
|
||||||
/* If it's not a scan code that starts with 0xE1 */
|
/* If it's not a scan code that starts with 0xE1 */
|
||||||
@@ -217,7 +199,4 @@ keyboard_handle(LPARAM lParam, int infocus)
|
|||||||
if (scancode != 0xFFFF)
|
if (scancode != 0xFFFF)
|
||||||
keyboard_input(!(rawKB.Flags & RI_KEY_BREAK), scancode);
|
keyboard_input(!(rawKB.Flags & RI_KEY_BREAK), scancode);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
free(raw);
|
|
||||||
}
|
}
|
||||||
|
@@ -58,32 +58,11 @@ win_mouse_init(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
win_mouse_handle(LPARAM lParam, int infocus)
|
win_mouse_handle(PRAWINPUT raw)
|
||||||
{
|
{
|
||||||
uint32_t ri_size = 0;
|
RAWMOUSE state = raw->data.mouse;
|
||||||
UINT size;
|
|
||||||
RAWINPUT *raw;
|
|
||||||
RAWMOUSE state;
|
|
||||||
static int x, y;
|
static int x, y;
|
||||||
|
|
||||||
if (! infocus) return;
|
|
||||||
|
|
||||||
GetRawInputData((HRAWINPUT)lParam, RID_INPUT, NULL,
|
|
||||||
&size, sizeof(RAWINPUTHEADER));
|
|
||||||
|
|
||||||
raw = (RAWINPUT*)malloc(size);
|
|
||||||
if (raw == NULL) return;
|
|
||||||
|
|
||||||
/* Here we read the raw input data for the mouse */
|
|
||||||
ri_size = GetRawInputData((HRAWINPUT)(lParam), RID_INPUT,
|
|
||||||
raw, &size, sizeof(RAWINPUTHEADER));
|
|
||||||
if (ri_size != size) goto err;
|
|
||||||
|
|
||||||
/* If the input is not a mouse, we ignore it */
|
|
||||||
if (raw->header.dwType != RIM_TYPEMOUSE) goto err;
|
|
||||||
|
|
||||||
state = raw->data.mouse;
|
|
||||||
|
|
||||||
/* read mouse buttons and wheel */
|
/* read mouse buttons and wheel */
|
||||||
if (state.usButtonFlags & RI_MOUSE_LEFT_BUTTON_DOWN)
|
if (state.usButtonFlags & RI_MOUSE_LEFT_BUTTON_DOWN)
|
||||||
mousestate.buttons |= 1;
|
mousestate.buttons |= 1;
|
||||||
@@ -120,9 +99,6 @@ win_mouse_handle(LPARAM lParam, int infocus)
|
|||||||
mousestate.dx += state.lLastX;
|
mousestate.dx += state.lLastX;
|
||||||
mousestate.dy += state.lLastY;
|
mousestate.dy += state.lLastY;
|
||||||
}
|
}
|
||||||
|
|
||||||
err:
|
|
||||||
free(raw);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@@ -1238,12 +1238,30 @@ input_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|||||||
{
|
{
|
||||||
switch (message) {
|
switch (message) {
|
||||||
case WM_INPUT:
|
case WM_INPUT:
|
||||||
keyboard_handle(lParam, infocus);
|
if (infocus) {
|
||||||
#ifndef USE_DINPUT
|
UINT size = 0;
|
||||||
win_mouse_handle(lParam, infocus);
|
PRAWINPUT raw = NULL;
|
||||||
#endif
|
|
||||||
break;
|
|
||||||
|
|
||||||
|
/* Here we read the raw input data */
|
||||||
|
GetRawInputData((HRAWINPUT)lParam, RID_INPUT, NULL, &size, sizeof(RAWINPUTHEADER));
|
||||||
|
raw = (PRAWINPUT)malloc(size);
|
||||||
|
if (GetRawInputData((HRAWINPUT)lParam, RID_INPUT, raw, &size, sizeof(RAWINPUTHEADER)) == size) {
|
||||||
|
switch(raw->header.dwType)
|
||||||
|
{
|
||||||
|
case RIM_TYPEKEYBOARD:
|
||||||
|
keyboard_handle(raw);
|
||||||
|
break;
|
||||||
|
case RIM_TYPEMOUSE:
|
||||||
|
win_mouse_handle(raw);
|
||||||
|
break;
|
||||||
|
case RIM_TYPEHID:
|
||||||
|
win_joystick_handle(raw);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
free(raw);
|
||||||
|
}
|
||||||
|
break;
|
||||||
case WM_SETFOCUS:
|
case WM_SETFOCUS:
|
||||||
infocus = 1;
|
infocus = 1;
|
||||||
if (! hook_enabled) {
|
if (! hook_enabled) {
|
||||||
|
Reference in New Issue
Block a user