引用: root@g2uliot:~# [ 1904.533449] usb 1-1.2: new low-speed USB device number 5 using ehci-platform
[ 1904.782050] input: USB Gamepad as /devices/platform/soc/11c70100.usb/usb1/1-1/1-1.2/1-1.2:1.0/0003:0810:0001.0002/input/input2
[ 1904.814048] hid-generic 0003:0810:0001.0002: input: USB HID v1.10 Joystick [ USB Gamepad ] on usb-11c70100.usb-1.2/input0
引用: root@g2uliot:~# cat /proc/bus/input/devices
I: Bus=0000 Vendor=0000 Product=0000 Version=0000
N: Name="ADS7846 Touchscreen"
P: Phys=spi1.0/input0
S: Sysfs=/devices/platform/soc/1004ac00.spi/spi_master/spi1/spi1.0/input/input0
U: Uniq=
H: Handlers=event0
B: PROP=0
B: EV=b
B: KEY=400 0 0 0 0 0 0 0 0 0 0
B: ABS=1000003
I: Bus=0003 Vendor=0810 Product=0001 Version=0110
N: Name=" USB Gamepad "
P: Phys=usb-11c70100.usb-1.2/input0
S: Sysfs=/devices/platform/soc/11c70100.usb/usb1/1-1/1-1.2/1-1.2:1.0/0003:0810:0001.0002/input/input2
U: Uniq=
H: Handlers=js0 event1
B: PROP=0
B: EV=1b
B: KEY=fff 0 0 0 0 0 0 0 0 0
B: ABS=30027
B: MSC=10
root@g2uliot:~#
引用: root@g2uliot:~# cat /dev/input/event1 | hexdump -C
00000000 8c 3b 67 5f 8c 55 05 00 04 00 04 00 03 00 09 00 |.;g_.U..........|
00000010 8c 3b 67 5f 8c 55 05 00 01 00 22 01 01 00 00 00 |.;g_.U....".....|
00000020 8c 3b 67 5f 8c 55 05 00 00 00 00 00 00 00 00 00 |.;g_.U..........|
00000030 8c 3b 67 5f 8a 3d 09 00 04 00 04 00 03 00 09 00 |.;g_.=..........|
00000040 8c 3b 67 5f 8a 3d 09 00 01 00 22 01 00 00 00 00 |.;g_.=....".....|
00000050 8c 3b 67 5f 8a 3d 09 00 00 00 00 00 00 00 00 00 |.;g_.=..........|
00000060 8d 3b 67 5f 07 f9 09 00 03 00 00 00 00 00 00 00 |.;g_............|
00000070 8d 3b 67 5f 07 f9 09 00 00 00 00 00 00 00 00 00 |.;g_............|
00000080 8d 3b 67 5f 4b 89 0c 00 03 00 00 00 7f 00 00 00 |.;g_K...........|
00000090 8d 3b 67 5f 4b 89 0c 00 00 00 00 00 00 00 00 00 |.;g_K...........|
000000a0 8e 3b 67 5f c8 0f 01 00 03 00 01 00 00 00 00 00 |.;g_............|
000000b0 8e 3b 67 5f c8 0f 01 00 00 00 00 00 00 00 00 00 |.;g_............|
000000c0 8e 3b 67 5f c9 03 03 00 03 00 01 00 7f 00 00 00 |.;g_............|
000000d0 8e 3b 67 5f c9 03 03 00 00 00 00 00 00 00 00 00 |.;g_............|
000000e0 8e 3b 67 5f 07 94 05 00 03 00 00 00 ff 00 00 00 |.;g_............|
000000f0 8e 3b 67 5f 07 94 05 00 00 00 00 00 00 00 00 00 |.;g_............|
00000100 8e 3b 67 5f 08 88 07 00 03 00 00 00 7f 00 00 00 |.;g_............|
00000110 8e 3b 67 5f 08 88 07 00 00 00 00 00 00 00 00 00 |.;g_............|
00000120 8e 3b 67 5f cb 50 0b 00 03 00 01 00 ff 00 00 00 |.;g_.P..........|
00000130 8e 3b 67 5f cb 50 0b 00 00 00 00 00 00 00 00 00 |.;g_.P..........|
00000140 8e 3b 67 5f c7 44 0d 00 03 00 01 00 7f 00 00 00 |.;g_.D..........|
00000150 8e 3b 67 5f c7 44 0d 00 00 00 00 00 00 00 00 00 |.;g_.D..........|
00000160 8f 3b 67 5f 4a 9b 09 00 03 00 00 00 ff 00 00 00 |.;g_J...........|
00000170 8f 3b 67 5f 4a 9b 09 00 00 00 00 00 00 00 00 00 |.;g_J...........|
00000180 8f 3b 67 5f 8a 2b 0c 00 03 00 00 00 7f 00 00 00 |.;g_.+..........|
00000190 8f 3b 67 5f 8a 2b 0c 00 00 00 00 00 00 00 00 00 |.;g_.+..........|
000001a0 90 3b 67 5f d0 15 00 00 04 00 04 00 09 00 09 00 |.;g_............|
000001b0 90 3b 67 5f d0 15 00 00 01 00 28 01 01 00 00 00 |.;g_......(.....|
000001c0 90 3b 67 5f d0 15 00 00 00 00 00 00 00 00 00 00 |.;g_............|
000001d0 90 3b 67 5f 89 ea 01 00 04 00 04 00 09 00 09 00 |.;g_............|
000001e0 90 3b 67 5f 89 ea 01 00 01 00 28 01 00 00 00 00 |.;g_......(.....|
000001f0 90 3b 67 5f 89 ea 01 00 00 00 00 00 00 00 00 00 |.;g_............|
00000200 90 3b 67 5f 4a 42 03 00 04 00 04 00 0a 00 09 00 |.;g_JB..........|
00000210 90 3b 67 5f 4a 42 03 00 01 00 29 01 01 00 00 00 |.;g_JB....).....|
00000220 90 3b 67 5f 4a 42 03 00 00 00 00 00 00 00 00 00 |.;g_JB..........|
00000230 90 3b 67 5f 89 d2 05 00 04 00 04 00 0a 00 09 00 |.;g_............|
00000240 90 3b 67 5f 89 d2 05 00 01 00 29 01 00 00 00 00 |.;g_......).....|
00000250 90 3b 67 5f 89 d2 05 00 00 00 00 00 00 00 00 00 |.;g_............|
00000260 90 3b 67 5f 87 c6 07 00 03 00 01 00 00 00 00 00 |.;g_............|
00000270 90 3b 67 5f 87 c6 07 00 00 00 00 00 00 00 00 00 |.;g_............|
00000280 90 3b 67 5f 49 9b 09 00 03 00 01 00 7f 00 00 00 |.;g_I...........|
00000290 90 3b 67 5f 49 9b 09 00 00 00 00 00 00 00 00 00 |.;g_I...........|
000002a0 90 3b 67 5f c8 56 0a 00 04 00 04 00 01 00 09 00 |.;g_.V..........|
000002b0 90 3b 67 5f c8 56 0a 00 01 00 20 01 01 00 00 00 |.;g_.V.... .....|
000002c0 90 3b 67 5f c8 56 0a 00 00 00 00 00 00 00 00 00 |.;g_.V..........|
000002d0 90 3b 67 5f 8b 2b 0c 00 04 00 04 00 01 00 09 00 |.;g_.+..........|
000002e0 90 3b 67 5f 8b 2b 0c 00 01 00 20 01 00 00 00 00 |.;g_.+.... .....|
000002f0 90 3b 67 5f 8b 2b 0c 00 00 00 00 00 00 00 00 00 |.;g_.+..........|
引用: /* Query a button's state.
Returns 1 if button #b is pressed. */
int nes_key_state(int b)
{
ALLEGRO_KEYBOARD_STATE state;
al_get_keyboard_state(&state);
switch (b)
{
case 0: // On / Off
return 1;
case 1: // A
return al_key_down(&state, ALLEGRO_KEY_K);
case 2: // B
return al_key_down(&state, ALLEGRO_KEY_J);
case 3: // SELECT
return al_key_down(&state, ALLEGRO_KEY_U);
case 4: // START
return al_key_down(&state, ALLEGRO_KEY_I);
case 5: // UP
return al_key_down(&state, ALLEGRO_KEY_W);
case 6: // DOWN
return al_key_down(&state, ALLEGRO_KEY_S);
case 7: // LEFT
return al_key_down(&state, ALLEGRO_KEY_A);
case 8: // RIGHT
return al_key_down(&state, ALLEGRO_KEY_D);
default:
return 1;
}
}
引用: #include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
int s_keys_fd = -1;
uint32_t s_keys_state = 0;
void* key_poll(void* arg)
{
char ret[2];
struct input_event t;
s_keys_fd = open((char*)arg, O_RDONLY);
if(s_keys_fd <= 0)
{
printf("open %s device error!n",(char*)arg);
return 0;
}
while(1)
{
if(read(s_keys_fd, &t, sizeof(t)) == sizeof(t))
{
if(t.type==EV_KEY)
{
if(t.value==0 || t.value==1)
{
printf("key %d %sn", t.code, (t.value) ? "Pressed" : "Released");
//if(t.code == KEY_ESC)
// break;
}
}
else
{
///printf("type %d code %d value %dn", t.type, t.code, t.value);
}
}
}
return 0;
}
void key_init(void* arg)
{
pthread_t id;
/* 创建函数线程,并且指定函数线程要执行的函数 */
int res = pthread_create(&id,NULL,key_poll,arg);
assert(res == 0);
while(1)
{
}
exit(0);
}
int key_getstate(int key)
{
}
int main(int argc, char* argv[])
{
key_init(argv[1]);
while(1);
}
更多回帖