first
This commit is contained in:
parent
b5f71864f6
commit
7308578ae8
4
LICENSE
4
LICENSE
@ -3,7 +3,9 @@ Version 2, December 2004
|
|||||||
|
|
||||||
Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
|
Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
|
||||||
|
|
||||||
Everyone is permitted to copy and distribute verbatim or modified copies of this license document, and changing it is allowed as long as the name is changed.
|
Everyone is permitted to copy and distribute verbatim or modified
|
||||||
|
copies of this license document, and changing it is allowed as long
|
||||||
|
as the name is changed.
|
||||||
|
|
||||||
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
||||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||||
|
@ -1,2 +1,6 @@
|
|||||||
# autoclicker
|
modprobe uinput
|
||||||
|
cc main.c -o main
|
||||||
|
|
||||||
|
sudo ./main
|
||||||
|
|
||||||
|
Read mouse events and start if you press mouse5 or mouse4
|
105
main.c
Normal file
105
main.c
Normal file
@ -0,0 +1,105 @@
|
|||||||
|
/*
|
||||||
|
* LICENSE: WTFPL
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <limits.h>
|
||||||
|
#include <signal.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <sys/time.h>
|
||||||
|
#include <sys/ioctl.h>
|
||||||
|
#include <linux/uinput.h>
|
||||||
|
#include <linux/input.h>
|
||||||
|
|
||||||
|
/* For signal handler */
|
||||||
|
int uinput_fd;
|
||||||
|
int event_fd;
|
||||||
|
|
||||||
|
void emit(int fd, int type, int code, int val) {
|
||||||
|
struct input_event ie;
|
||||||
|
|
||||||
|
ie.type = type;
|
||||||
|
ie.code = code;
|
||||||
|
ie.value = val;
|
||||||
|
|
||||||
|
/* timestamp values below are ignored */
|
||||||
|
ie.time.tv_sec = 0;
|
||||||
|
ie.time.tv_usec = 0;
|
||||||
|
|
||||||
|
write(fd, &ie, sizeof(ie));
|
||||||
|
}
|
||||||
|
|
||||||
|
void press(int fd) {
|
||||||
|
puts("CLICK");
|
||||||
|
for (int i = 0; i < 10; i++) {
|
||||||
|
usleep(50000);
|
||||||
|
|
||||||
|
emit(fd, EV_KEY, BTN_LEFT, 1);
|
||||||
|
emit(fd, EV_SYN, SYN_REPORT, 0);
|
||||||
|
emit(fd, EV_KEY, BTN_LEFT, 0);
|
||||||
|
emit(fd, EV_SYN, SYN_REPORT, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void stop(int sig) {
|
||||||
|
(void)sig;
|
||||||
|
|
||||||
|
ioctl(uinput_fd, UI_DEV_DESTROY);
|
||||||
|
close(uinput_fd);
|
||||||
|
|
||||||
|
close(event_fd);
|
||||||
|
puts("Stoping...");
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char **argv) {
|
||||||
|
signal(SIGTERM, stop);
|
||||||
|
signal(SIGINT, stop);
|
||||||
|
|
||||||
|
uinput_fd = open("/dev/uinput", O_WRONLY | O_NONBLOCK);
|
||||||
|
if (uinput_fd < 0) {
|
||||||
|
fprintf(stderr, "autoclicker: /dev/uinput: %s\n", strerror(errno));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Keyboard events */
|
||||||
|
event_fd = open("/dev/input/event1", O_RDONLY);
|
||||||
|
if (event_fd < 0) {
|
||||||
|
close(uinput_fd);
|
||||||
|
|
||||||
|
fprintf(stderr, "autoclicker: /dev/input/eventX: %s\n", strerror(errno));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Setup uinput */
|
||||||
|
ioctl(uinput_fd, UI_SET_EVBIT, EV_KEY);
|
||||||
|
ioctl(uinput_fd, UI_SET_KEYBIT, BTN_LEFT);
|
||||||
|
|
||||||
|
/* Setup struct */
|
||||||
|
struct uinput_setup usetup;
|
||||||
|
memset(&usetup, 0, sizeof(usetup));
|
||||||
|
|
||||||
|
usetup.id.bustype = BUS_USB;
|
||||||
|
usetup.id.vendor = 0x123;
|
||||||
|
usetup.id.product = 0x123;
|
||||||
|
snprintf(usetup.name, UINPUT_MAX_NAME_SIZE, "autoclicker");
|
||||||
|
|
||||||
|
ioctl(uinput_fd, UI_DEV_SETUP, &usetup);
|
||||||
|
ioctl(uinput_fd, UI_DEV_CREATE);
|
||||||
|
|
||||||
|
/* Main */
|
||||||
|
int flag = 0;
|
||||||
|
struct input_event event;
|
||||||
|
|
||||||
|
while (read(event_fd, &event, sizeof(event)) > 0) {
|
||||||
|
printf("You cliekced: %d\n", event.code);
|
||||||
|
if (event.code == 275 || event.code == 276)
|
||||||
|
press(uinput_fd);
|
||||||
|
}
|
||||||
|
|
||||||
|
stop(0);
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user