add time between two clicks

This commit is contained in:
rick 2022-12-17 02:31:33 +01:00
parent 55a4f5d8ab
commit 6126d62097
Signed by: Rick
GPG key ID: 4A6223D66294EB20
4 changed files with 39 additions and 8 deletions

View file

@ -5,8 +5,17 @@
#include "event.h"
#include "read_file.h"
void readfile(FILE *file)
args_readfile * args_rf_init(FILE *file, int time_sleep)
{
args_readfile *ret = (args_readfile *) malloc(sizeof(args_readfile));
ret->file = file;
ret->time_sleep = time_sleep;
return ret;
}
void readfile(args_readfile *args)
{
FILE *file = args->file;
xdo_t *x_t = xdo_new(NULL);
event *current_event = new_event();
@ -19,7 +28,7 @@ void readfile(FILE *file)
fread(current_event, sizeof(event), 1, file);
if (ferror(file))
{
printf("Erreur !!");
fprintf(stderr, "Erreur à la lecture du fichier");
break;
}
@ -31,13 +40,12 @@ void readfile(FILE *file)
y = current_event->y;
xdo_move_mouse(x_t, x, y, 0);
sleep(1);
if (left) xdo_click_window(x_t, CURRENTWINDOW, 1);
if (middle) xdo_click_window(x_t, CURRENTWINDOW, 2);
if (right) xdo_click_window(x_t, CURRENTWINDOW, 3);
sleep(5);
sleep(args->time_sleep);
}
free(current_event);

View file

@ -1,4 +1,19 @@
#ifndef READ_FILE
#define READ_FILE
void readfile(FILE *file);
/*
* Arguments pour la lecture du fichier.
*/
typedef struct {
/* le fichier à lire */
FILE *file;
/* le temps entre chaque clic */
int time_sleep;
} args_readfile;
/* Initialise les arguments. Doit être libérer par l'appelant. */
args_readfile * args_rf_init(FILE *file, int time_sleep);
/* Lit un fichier et répète les clics avec une pause entre chaque. */
void readfile(args_readfile *args);
#endif

View file

@ -15,10 +15,13 @@ ui_infos * init_ui(char *name)
strcpy(ret->name, name);
ret->file = fopen(name, "w+");
ret->is_recording = 0;
ret->args_rf = args_rf_init(ret->file, 1);
return ret;
}
void free_ui(ui_infos *ptr)
{
if (ptr->args_rf != NULL) free(ptr->args_rf);
if (ptr->file != NULL) fclose(ptr->file);
if (ptr->name != NULL) free(ptr->name);
free(ptr);
@ -41,9 +44,8 @@ int draw_ui(ui_infos *ptr)
* Liste déroulantes des fenetres pour savoir faire les clics
*/
igText("Fichier : %s", ptr->name);
igBegin("Test", NULL, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoDecoration);
igText("Test");
igText("Fichier : %s", ptr->name);
if (ptr->is_recording)
{
@ -71,10 +73,14 @@ int draw_ui(ui_infos *ptr)
}
}
igSetNextItemWidth(100.0);
igInputInt("Temps de repos entre chaque clic (s)", &ptr->args_rf->time_sleep, 1, 10, 0);
if (ptr->args_rf->time_sleep <= 0) ptr->args_rf->time_sleep = 1;
if (igButton("Replay", (ImVec2) {0, 0}))
{
rewind(ptr->file);
readfile(ptr->file);
readfile(ptr->args_rf);
}
}

View file

@ -1,12 +1,14 @@
#ifndef UI
#define UI
#include <pthread.h>
#include "read_file.h"
typedef struct {
char *name;
FILE *file;
char is_recording;
pthread_t pid;
args_readfile *args_rf;
} ui_infos;
ui_infos * init_ui(char *name);