Mario Mastrodicasa
|
devi-hid and /dev/devi/keyboard0
|
Mario Mastrodicasa
02/27/2009 4:11 PM
post23143
|
devi-hid and /dev/devi/keyboard0
I hope this is the right place.
I have written this simple code in order to understand what I am able to capture from /dev/devi/keyboard0 using devi-hid
as a resource manager.
I have launched devi-hid as:
/usr/photon/bin/devi-hid -rP kbd keyboard /usr/photon/keyboard/it_IT_102.kdef
#include <cstdlib>
#include <iostream>
#include <stdio.h>
#include <termios.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/dcmd_input.h>
#include <devctl.h>
#include <string.h>
int main(int argc, char *argv[]) {
std::cout << "keyboard test data_len:"<< sizeof(struct _keyboard_packet) << std::endl;
int keyFD = open("/dev/devi/keyboard0", O_RDWR | O_NDELAY);
struct _keyboard_packet buf;
int index = 0, n;
while (1)
{
if ((n = read(keyFD, &buf, sizeof(buf))) > 0)
{
index++;
printf("KEY -> %d: char:%d modifiers:%x flags:%x key_cap:%x %c key_sym:%x %c key_scan:%x %c\n", index, n, buf.data
.modifiers, buf.data.flags, buf.data.key_cap, buf.data.key_cap, buf.data.key_sym, buf.data.key_sym, buf.data.key_scan,
buf.data.key_scan);
usleep(100000);
}
}
return EXIT_SUCCESS;
}
I have tried some tests but I cannot understand some things.
When I press a key I can read an entire "struct _keyboard_packet" from the fd. When release I receive another packet and
the information seems strange.
I cannot understand how interpret, in the correct manner, the field in the structure.
Reading the documenation I have found something in the photon KeyEvent, but, according to the documentation and seeing
the output of the test program, the means of modifiers and flags must be interpret in the opposite way.
When I press and release a key two event are produced; the output of the consecutive pressure of 'a' and 'shift + 'a' is
:
KEY -> 1: char:28 modifiers:7fc6d6c flags:0 key_cap:e1 á key_sym:61 a key_scan:61 a
KEY -> 2: char:28 modifiers:7fc6d6c flags:0 key_cap:1a0 key_sym:61 a key_scan:94 ”
KEY -> 3: char:28 modifiers:7fc6d6c flags:1 key_cap:e1 á key_sym:f0e2 â key_scan:f0e2 â
KEY -> 4: char:28 modifiers:7fc6d6c flags:1 key_cap:e1 á key_sym:61 a key_scan:41 A
KEY -> 5: char:28 modifiers:7fc6d6c flags:1 key_cap:1a0 key_sym:61 a key_scan:94 ”
KEY -> 6: char:28 modifiers:7fc6d6c flags:0 key_cap:1a0 key_sym:f0e2 â key_scan:bc ¼
Each row is produced on every key press/release event.
I don't understand what means the value of key_cap? It is associated, using some undocumented flag, to the kind of event
?
Key_sym is always the hardware button that have generated the event, but key_scan what means? In some situation (row 4)
is the right expected character, but the other row?
'flags' is a bitmask that tracks modifier button, while 'modifiers' is always the same, what means it's value?
Where I can find when a button is pressed or released? I must track all event in the past and make a sort of match
algorithm?
Thanks.
Mario.
|
|
|