-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
sofakng
committed
Feb 24, 2023
0 parents
commit 8977b88
Showing
6 changed files
with
544 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#CC = gcc | ||
CC = /usr/local/src/arm-linux-musleabihf-cross/bin/arm-linux-musleabihf-gcc | ||
CFLAGS = -std=c99 -static -D_XOPEN_SOURCE=700 | ||
|
||
all: risd | ||
|
||
risd: main.o keys.o evdev.o sockets.o utility.o | ||
$(CC) $(CFLAGS) -o risd main.o keys.o evdev.o sockets.o utility.o | ||
|
||
main.o: main.c | ||
$(CC) $(CFLAGS) -c main.c | ||
|
||
keys.o: keys.c | ||
$(CC) $(CFLAGS) -c keys.c | ||
|
||
evdev.o: evdev.c | ||
$(CC) $(CFLAGS) -c evdev.c | ||
|
||
sockets.o: sockets.c | ||
$(CC) $(CFLAGS) -c sockets.c | ||
|
||
utility.o: utility.c | ||
$(CC) $(CFLAGS) -c utility.c | ||
|
||
clean: | ||
rm risd main.o keys.o evdev.o sockets.o utility.o | ||
|
||
upload: | ||
curl --insecure --user root:1 -T risd sftp://mister/root/risd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
#include <stdio.h> | ||
#include <string.h> | ||
#include <fcntl.h> | ||
#include <unistd.h> | ||
#include <linux/uinput.h> | ||
|
||
#include "evdev.h" | ||
#include "utility.h" | ||
|
||
int ev_fd; | ||
|
||
int ev_close(int fd) { | ||
ioctl(fd, UI_DEV_DESTROY); | ||
return close(fd); | ||
} | ||
|
||
int ev_open() | ||
{ | ||
int fd = open(DEVICE_PATH, O_WRONLY | O_NONBLOCK); | ||
|
||
if (fd < 0) | ||
{ | ||
fprintf(stderr, "Unable to open uinput device: %s\n", DEVICE_PATH); | ||
exit_with_error(1); | ||
} | ||
|
||
ioctl(fd, UI_SET_EVBIT, EV_KEY); | ||
for (int i=KEY_ESC; i<KEY_MAX; i++) { | ||
ioctl(fd, UI_SET_KEYBIT, i); | ||
} | ||
|
||
struct uinput_setup usetup; | ||
memset(&usetup, 0, sizeof(usetup)); | ||
usetup.id.bustype = BUS_USB; | ||
usetup.id.vendor = 0x1234; /* fake vendor */ | ||
usetup.id.product = 0x5678; /* fake product */ | ||
strcpy(usetup.name, DEVICE_NAME); | ||
ioctl(fd, UI_DEV_SETUP, &usetup); | ||
ioctl(fd, UI_DEV_CREATE); | ||
|
||
return fd; | ||
} | ||
|
||
void ev_emit(int fd, int type, int code, int val) { | ||
struct input_event ie = {0,}; | ||
ie.type = type; | ||
ie.code = code; | ||
ie.value = val; | ||
write(fd, &ie, sizeof(ie)); | ||
} | ||
|
||
void emulate_key_press(int fd, int key) { | ||
msleep(INTER_KEY_WAIT); | ||
ev_emit(fd, EV_KEY, key, 1); | ||
ev_emit(fd, EV_SYN, SYN_REPORT, 0); | ||
} | ||
|
||
void emulate_key_release(int fd, int key) { | ||
msleep(INTER_KEY_WAIT); | ||
ev_emit(fd, EV_KEY, key, 0); | ||
ev_emit(fd, EV_SYN, SYN_REPORT, 0); | ||
} | ||
|
||
void emulate_key(int fd, int key) { | ||
emulate_key_press(fd, key); | ||
emulate_key_release(fd, key); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
#include <linux/uinput.h> | ||
#include <string.h> | ||
#include <stdio.h> | ||
|
||
#include "keys.h" | ||
#include "utility.h" | ||
|
||
struct key_lookup keys[100]; | ||
|
||
int find_key (char* name) | ||
{ | ||
for (int i = 0; i < KEYLIST_SIZE; i++) | ||
{ | ||
if (strcmp(keys[i].name, name) == 0) | ||
return keys[i].code; | ||
} | ||
|
||
return -1; | ||
} | ||
|
||
struct key_lookup create_key (char* name, int code) | ||
{ | ||
struct key_lookup k; | ||
strcpy(k.name, name); | ||
k.code = code; | ||
|
||
return k; | ||
} | ||
|
||
void fill_keylist() | ||
{ | ||
int i=0; | ||
|
||
keys[i++] = create_key("KEY_0", KEY_0); | ||
keys[i++] = create_key("KEY_1", KEY_1); | ||
keys[i++] = create_key("KEY_2", KEY_2); | ||
keys[i++] = create_key("KEY_3", KEY_3); | ||
keys[i++] = create_key("KEY_4", KEY_4); | ||
keys[i++] = create_key("KEY_5", KEY_5); | ||
keys[i++] = create_key("KEY_6", KEY_6); | ||
keys[i++] = create_key("KEY_7", KEY_7); | ||
keys[i++] = create_key("KEY_8", KEY_8); | ||
keys[i++] = create_key("KEY_9", KEY_9); | ||
|
||
keys[i++] = create_key("KEY_D", KEY_D); | ||
keys[i++] = create_key("KEY_I", KEY_I); | ||
keys[i++] = create_key("KEY_S", KEY_S); | ||
keys[i++] = create_key("KEY_Q", KEY_Q); | ||
|
||
keys[i++] = create_key("KEY_SPACE", KEY_SPACE); | ||
|
||
keys[i++] = create_key("KEY_F1", KEY_F1); | ||
keys[i++] = create_key("KEY_F2", KEY_F2); | ||
keys[i++] = create_key("KEY_F3", KEY_F3); | ||
keys[i++] = create_key("KEY_F4", KEY_F4); | ||
keys[i++] = create_key("KEY_F5", KEY_F5); | ||
keys[i++] = create_key("KEY_F6", KEY_F6); | ||
keys[i++] = create_key("KEY_F7", KEY_F7); | ||
keys[i++] = create_key("KEY_F8", KEY_F8); | ||
keys[i++] = create_key("KEY_F9", KEY_F9); | ||
keys[i++] = create_key("KEY_F10", KEY_F10); | ||
keys[i++] = create_key("KEY_F11", KEY_F11); | ||
keys[i++] = create_key("KEY_F12", KEY_F12); | ||
|
||
keys[i++] = create_key("KEY_UP", KEY_UP); | ||
keys[i++] = create_key("KEY_DOWN", KEY_DOWN); | ||
keys[i++] = create_key("KEY_LEFT", KEY_LEFT); | ||
keys[i++] = create_key("KEY_RIGHT", KEY_RIGHT); | ||
|
||
keys[i++] = create_key("KEY_PAGEDOWN", KEY_PAGEDOWN); | ||
keys[i++] = create_key("KEY_UP", KEY_PAGEUP); | ||
|
||
keys[i++] = create_key("KEY_ENTER", KEY_ENTER); | ||
keys[i++] = create_key("KEY_RETURN", KEY_ENTER); | ||
|
||
keys[i++] = create_key("KEY_ESC", KEY_ESC); | ||
|
||
keys[i++] = create_key("WINKEY", KEY_LEFTMETA); | ||
keys[i++] = create_key("GUI", KEY_LEFTMETA); | ||
|
||
keys[i++] = create_key("CTRL", KEY_LEFTCTRL); | ||
keys[i++] = create_key("ALT", KEY_LEFTALT); | ||
keys[i++] = create_key("RALT", KEY_RIGHTALT); | ||
keys[i++] = create_key("SHIFT", KEY_LEFTSHIFT); | ||
|
||
keys[i++] = create_key("KEY_TAB", KEY_TAB); | ||
keys[i++] = create_key("KEY_BACKSLASH", KEY_BACKSLASH); | ||
keys[i++] = create_key("KEY_BACKSPACE", KEY_BACKSPACE); | ||
keys[i++] = create_key("KEY_DELETE", KEY_DELETE); | ||
keys[i++] = create_key("KEY_INSERT", KEY_INSERT); | ||
keys[i++] = create_key("KEY_TILDE", KEY_GRAVE); | ||
|
||
keys[i++] = create_key("KEY_PLUS", KEY_KPPLUS); | ||
keys[i++] = create_key("KEY_MINUS", KEY_KPMINUS); | ||
|
||
if (i > KEYLIST_SIZE) { | ||
fprintf(stderr, "Key list size is too large.\r\n"); | ||
exit_with_error(1); | ||
} | ||
} |
Oops, something went wrong.