-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinput_dx.c
77 lines (64 loc) · 1.59 KB
/
input_dx.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#ifdef WIN32
#include "main.h"
#include "dinput.h"
LPDIRECTINPUT lpdi = NULL;
LPDIRECTINPUTDEVICE lpdiMouse;
DIMOUSESTATE mouse;
px_timer_t dx_mouse_timer;
void dx_timer_init( void )
{
timer_clear( &dx_mouse_timer );
}
BOOL dx_init( void )
{
HRESULT err;
GUID guid_mouse = GUID_SysMouse;
dx_timer_init();
err = DirectInputCreate(GetModuleHandle(NULL), DIRECTINPUT_VERSION, &lpdi, NULL);
if (FAILED(err))
return FALSE;
err = IDirectInput_CreateDevice(lpdi, &guid_mouse, &lpdiMouse, NULL);
if ( err != DI_OK )
return FALSE;
err = IDirectInputDevice_SetDataFormat(lpdiMouse, &c_dfDIMouse);
if(err != DI_OK)
return FALSE;
err = IDirectInputDevice_SetCooperativeLevel(
lpdiMouse, GetActiveWindow(), DISCL_NONEXCLUSIVE | DISCL_BACKGROUND
);
if(err != DI_OK)
return FALSE;
err = IDirectInputDevice_Acquire(lpdiMouse);
return TRUE;
}
void dx_read_mouse( void )
{
static float runs = 0.0f;
HRESULT hr = IDirectInputDevice_GetDeviceState(
lpdiMouse, sizeof(DIMOUSESTATE), &mouse
);
runs++;
if( hr == DI_OK )
{
if(mouse.lX + mouse.lY > 0)
{
//float seconds = timer_run( &dx_mouse_timer );
//float ms = seconds * 1000.0f;
//float per_second = runs / seconds;
//p("dx/s: %f s:%f ms:%f r:%f\n",per_second,seconds,ms,runs);
//p("x %d y %d\n", mouse.lX, mouse.lY);
p("dx runs %f\n",runs);
runs = 0.0f;
}
}
else if( hr == DIERR_INPUTLOST )
{
p("dx input lost - reacuiring...\n");
IDirectInputDevice_Acquire(lpdiMouse);
}
else
{
p("mouse error: %d\n",hr);
}
}
#endif // WIN32