]>
git.gir.st - sendHID.git/blob - main.c
2 description: sends a sequence of keystrokes to the hid device.
4 device file (e.g. /dev/hidg0)
5 keyboard layout (e.g. en_us; only a limited number are supported and they do not follow unix-naming conventions for convenience)
6 the string to send (as whitespace is important, the `echo` way of concatenating all parameters is not supported. if your string has white space in it and you are in an interactive session, quote your string.
11 #include "scancodes.h"
13 void send_key ( FILE * hid_dev
, unsigned short key
, unsigned short mod
);
15 int main ( int argc
, char ** argv
) {
17 fprintf ( stderr
, "Usage: %s <device file> <layout> \" <string> \"\n " , argv
[ 0 ]);
20 FILE * hid_dev
= fopen ( "/dev/hidg0" , "w" );
21 for ( int i
= 0 ; i
< strlen ( argv
[ 3 ]); i
++) {
23 char tmp
[ UTF8_MAX_LENGTH
] = { argv
[ 3 ][ i
], argv
[ 3 ][ i
+ 1 ], argv
[ 3 ][ i
+ 2 ], '\0' };
24 //TODO: replace by something less stupid
25 if ( argv
[ 3 ][ i
] < 128 ) { // not multi byte
27 } else { // is multi byte
28 if ( argv
[ 3 ][ i
] < 0xe0 ) {
29 i
++; //skip next thing
32 i
+= 2 ; //WARN: fails on utf8 > 3 byte
36 struct keysym
* s
= toscan ( tmp
);
38 fprintf ( stderr
, "Key Symbol not found. \n " );
41 switch ( atoi ( argv
[ 2 ])) {
43 fprintf ( stderr
, "This keyboard layout is reserved. \n " );
46 send_key ( hid_dev
, s
-> en_us
. key
, s
-> en_us
. mod
);
49 send_key ( hid_dev
, s
-> de_at
. key
, s
-> de_at
. mod
); //, s->de_at.is_dead);
51 case 3 : //de_at-nodeadkeys
52 send_key ( hid_dev
, s
-> de_at
. key
, s
-> de_at
. mod
);
55 fprintf ( stderr
, "Unrecognised keyboard layout. \n " );
58 send_key ( hid_dev
, '\0' , '\0' );
65 void send_key ( FILE * hid_dev
, unsigned short key
, unsigned short mod
) {
66 fprintf ( hid_dev
, "%c%c%c%c%c%c%c%c" , mod
, '\0' , key
, '\0' , '\0' , '\0' , '\0' , '\0' );