-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathf5.c
More file actions
124 lines (91 loc) Β· 3.11 KB
/
f5.c
File metadata and controls
124 lines (91 loc) Β· 3.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/*
* Send fake f5 key event, best suited for refreshing Pardus page
* while waiting for a release
*
* compile with
* gcc f5.c -lX11 -lXtst -o f5
*
* Onur KΓΌΓ§ΓΌk <onur@pardus.org.tr> 20 Jan 2011
*/
#include <X11/Xlib.h>
#include <X11/Intrinsic.h>
#include <X11/extensions/XTest.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int repeat = 10;
int sleepinterval = 2;
static void sendPointerMotion(Display * disp, int motionX, int motionY, int relative) {
XEvent event;
/* Get the current pointer position */
XQueryPointer (disp, RootWindow (disp, 0),
&event.xbutton.root, &event.xbutton.window,
&event.xbutton.x_root, &event.xbutton.y_root,
&event.xbutton.x, &event.xbutton.y,
&event.xbutton.state);
if (relative) {
/* Fake the pointer movement to new relative position */
XTestFakeMotionEvent(disp, 0, event.xbutton.x + motionX,
event.xbutton.y + motionY, 0);
} else {
/* Fake the pointer movement to new absolute position */
XTestFakeMotionEvent (disp, 0, motionX, motionY, 0);
}
XSync(disp, False);
}
static void sendPointerClick(Display * disp, int pointerButton) {
/* Fake the mouse button Press and Release events */
XTestFakeButtonEvent (disp, pointerButton, True, 0);
XTestFakeButtonEvent (disp, pointerButton, False, 0);
XSync(disp, False);
}
/* Send Fake Key Event */
static void sendKey (Display * disp, KeySym keysym, KeySym modsym) {
KeyCode keycode = 0, modcode = 0;
keycode = XKeysymToKeycode (disp, keysym);
if (keycode == 0)
return;
XTestGrabControl (disp, True);
/* Generate modkey press */
if (modsym != 0) {
modcode = XKeysymToKeycode(disp, modsym);
XTestFakeKeyEvent (disp, modcode, True, 0);
}
/* Generate regular key press and release */
XTestFakeKeyEvent (disp, keycode, True, 0);
XTestFakeKeyEvent (disp, keycode, False, 0);
/* Generate modkey release */
if (modsym != 0)
XTestFakeKeyEvent (disp, modcode, False, 0);
XSync (disp, False);
XTestGrabControl (disp, False);
}
void printusage(void) {
printf("\n");
printf("Automatic F5 pressing tool, start with \n");
printf("\n");
printf("f5 <repeat count> <delay in seconds> \n");
printf("\n");
printf("running as repeat=%d delay=%d\n", repeat, sleepinterval);
printf("\n");
}
int main (int argc, char *argv[]) {
Display *disp = XOpenDisplay (NULL);
int i;
if (argc > 1)
repeat = atoi(argv[1]);
if (argc > 2)
sleepinterval = atoi(argv[2]);
printusage();
for (i = 0; i < repeat; i++) {
sleep (sleepinterval);
//sendKey (disp, XK_F5, XK_Alt_L); /* press Alt-F5 */
//sendPointerClick(disp, 3); /* click right mouse button */
//sendPointerMotion(disp, 50, 50, 1); /* move mouse to 50 pixels right and 50 pixel below */
sendKey (disp, XK_F5, 0); /* press F5 */
printf("pressing f5\n");
}
XCloseDisplay (disp);
printf("\n");
return 0;
}