Linux Keyboard Event Capturing /Dev/Inputx

Linux keyboard event capturing /dev/inputX

Thank you for the clue about ls -l /dev/input/by-id it helped me a lot !.

defenderdz@defenderdz-pc:~$ ls -l /dev/input/by-id | grep kbd
lrwxrwxrwx 1 root root 9 nov. 28 14:04 usb-Logitech_USB_Receiver-event-kbd -> ../event7
lrwxrwxrwx 1 root root 10 nov. 29 00:33 usb-NOVATEK_USB_Keyboard-event-kbd -> ../event26
lrwxrwxrwx 1 root root 9 nov. 28 14:04 usb-SONiX_USB_DEVICE-event-kbd -> ../event3
defenderdz@defenderdz-pc:~$

'kbd' is the suffix used for keyboard devices (I have 3 keyboards connected).

Your error is that you're accessing the wrong folder :

/dev/input/ instead of /dev/input/by-id

In my example the correct path is :

defenderdz@defenderdz-pc:~$ sudo cat /dev/input/by-id/usb-NOVATEK_USB_Keyboard-event-kbd
���]�I���]�I���]�Ia���]�b���]�b���]�b���]�����]�����]��s���]����]����]����]�>
���]�>
���]�>
d���]�8
���]�8
���]�8
���]�����]�����]��s���]H|���]H|���]H|���]�����]�� ���]��d���]Ǵ���]Ǵ ���]Ǵ

In your case

neel@pc1$ sudo cat /dev/input/by-id/usb-Plus_More_Enterprise_LTD._USB-compliant_keyboard-event-kbd

I'm not saying that it's the best solution but it works fine for me.
You can even create an automatic detection of the keyboard by parsing the ls result ...

Reading keyboard events from /dev/input/event* in assembler

That shouldn't even assemble, please don't use conflicting size suffixes ... movl for a 64 bit operation makes no sense even if you are lucky that the assembler accepts it (mine doesn't, and rightly so). Also your problem is not with reading the events. You can't even open the file, so you should have focused your question on that. The reason it doesn't work is that the function number for open is 2, 5 means fstat. Also, the arguments should be placed in rsi, rdi and rdx (but note that mode does not have to be passed if you don't ask for O_CREAT):

movl $2, %eax              # sys_open
movabsq $file, %rdi # path
movl $00, %esi # readonly flag
syscall

movl %rax, %rsp is also a bad idea, you probably wanted something else like movq %rax, -8(%rsp) or whatever is appropriate.

PS: at least on my system you need root privileges to open /dev/input/event0.

Virtual Keyboard (Linux/libevdev) - sending event

I solved this problem. Screen wasn't connect to BeagleBone/Raspberry and system was can't send character to screen.

Capturing Display / Monitor Images, Sending Keyboard Input on Linux

I finally have a solution. I believe UrT loads OpenGL on its own so that things such as wallhacks, etc are not possible. Then the best remaining option is taking X screenshots. This worked quite fast, even from a scripting language like Python. The following code takes successive screenshots and displays them as an animation through OpenCV. You need to start UrT in minimized mode of course. The rest of the details are in my project.

import gtk.gdk
import PIL
from opencv.cv import *
from opencv.highgui import *
from opencv.adaptors import PIL2Ipl

w = gtk.gdk.get_default_root_window()
sz = w.get_size()
print "The size of the window is %d x %d" % sz

size_x = 600
size_y = 400
start_x = 0
start_y = 100
end_x = start_x+size_x
end_y = start_y+size_y
box = (start_x, start_y, start_x+size_x, start_y+size_y)

while True:
pb = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB,False,8,sz[0],sz[1])
pb = pb.get_from_drawable(w,w.get_colormap(),0,0,0,0,sz[0],sz[1])
width,height = pb.get_width(),pb.get_height()
im = PIL.Image.fromstring("RGB",(width,height),pb.get_pixels())
im = im.crop(box)
cv_img = PIL2Ipl(im)
cvNamedWindow("fps")
cvShowImage("fps", cv_img)
cvWaitKey(30)

Also, for sending keys to the game, the method above did not work, I had to use xdotool in order to send forward walk key to UrT,

xdotool search --name ioUrbanTerror  windowactivate keydown W

/dev/input keyboard format

/dev/input/by-path/platform-i8042-serio-0-event-kbd is just a symlink to /dev/input/eventX event device file. Data can be read from event device files as

struct input_event {
struct timeval time;
__u16 type;
__u16 code;
__s32 value;
};

defined in /usr/include/linux/input.h.

Possible values of type are prefixed with EV_.
Possible values of code depend on type. They are prefixed with KEY_ or BTN_ or REL_ or so on.
Possible values of value depend on both type and code. For example for key-press events value equals 1 and for key-release events 0.

You can examine event data with:

evtest /dev/input/eventX

where X is the event device number of your keyboard (or any other event device). One key press or release normally emits three events (EV_MSC, EV_KEY and EV_SYN).



Related Topics



Leave a reply



Submit