0,0 → 1,163 |
--- a/ventriloctrl-0.5/ventriloctrl.c 2008-08-23 10:23:03.000000000 +0200 |
+++ b/ventriloctrl-0.5/ventriloctrl.c 2009-06-20 01:40:40.000000000 +0200 |
@@ -16,6 +16,7 @@ |
/* Configuration */ |
#define SIMULATEKEY XK_A // Simulate Key Press |
#define VENTRILO "Ventrilo" // Ventrilo Window Name |
+#define OTHERKEY XK_B //Key send to Ventrillo if other key is being pressed |
|
/* Global Variables */ |
Display *display; |
@@ -54,14 +55,14 @@ |
{ |
// Variables |
int i; |
- |
+ |
// Get the "Window" Tree |
Window root; |
Window parent; |
Window *children = 0; |
unsigned int childrenCount = 0; |
XQueryTree(display, parentWindow, &root, &parent, &children, &childrenCount); |
- |
+ |
// Crawl the "Window" Tree |
char *window_name = 0; |
Window *window = 0; |
@@ -74,7 +75,7 @@ |
} |
XFree(window_name); |
} |
- |
+ |
// Crawl the Child and Look For "windowName" |
window = find_window(display, children[i], windowName); |
if (window != 0) { |
@@ -82,10 +83,10 @@ |
return window; |
} |
} |
- |
+ |
// Free the Children! lol |
if (children != 0) XFree(children); |
- |
+ |
// Return |
return 0; |
} |
@@ -94,42 +95,43 @@ |
{ |
// Usage |
printf("\n"); |
- |
+ |
// Initialize "Display" |
display = XOpenDisplay(0); |
if (display == NULL) { |
printf("Error: Could not open display!\n"); |
return 1; |
} |
- |
+ |
// Initialize Root "Window" |
window = XDefaultRootWindow(display); |
if (!window) { |
printf("Error: Could not grab root window!\n"); |
return 2; |
} |
- |
+ |
// Initialize Ventrilo "Window" |
windowVentrilo = find_window(display, window, VENTRILO); |
if (!windowVentrilo) { |
printf("Error: Could not find Ventrilo window!\n"); |
return 3; |
} |
- |
+ |
// Convert Key String to Number |
unsigned int key = atoi(argv[2]); |
unsigned int simulatekey = XKeysymToKeycode(display, SIMULATEKEY); |
- |
+ unsigned int otherkey = XKeysymToKeycode(display, OTHERKEY); |
+ |
// Open the Input |
int device = open(argv[1], O_RDONLY); |
- |
+ |
// Loop |
struct input_event ev; |
XKeyEvent event; |
while (ventrilo_still_running()) { |
// Read from the Input |
read(device, &ev, sizeof(struct input_event)); |
- |
+ |
// Check Input |
if (ev.type == 1 && ev.code == key) { |
// Simulate Key Press/Release |
@@ -141,8 +143,18 @@ |
} |
XFlush(display); |
} |
+ else if (ev.type == 1 && ev.code != key) { |
+ // Send other key (this should prevent putting the user on afk status) |
+ event = create_key_event(display, *windowVentrilo, window, ev.value, otherkey, 0); |
+ if (ev.value == 1) { |
+ XSendEvent(event.display, event.window, True, KeyPressMask, (XEvent *) &event); |
+ } else { |
+ XSendEvent(event.display, event.window, True, KeyReleaseMask, (XEvent *) &event); |
+ } |
+ XFlush(display); |
+ } |
} |
- |
+ |
// Return |
return 0; |
} |
@@ -156,20 +168,20 @@ |
printf("then execute the command listed.\n"); |
printf("Press Ctrl+C when finished.\n"); |
printf("\n"); |
- |
+ |
// Open the Input |
int device = open(argv[1], O_RDONLY); |
- |
+ |
// Loop |
struct input_event ev; |
while (1) { |
// Read from the Input |
read(device, &ev, sizeof(struct input_event)); |
- |
+ |
// Print the Command |
if (ev.type == 1 && ev.value == 1) printf("%s %s %i\n", argv[0], argv[1], ev.code); |
} |
- |
+ |
// Return |
return 0; |
} |
@@ -180,7 +192,7 @@ |
// Programs |
if(argc == 2) return findkey(argc, argv); // Find Key |
if(argc == 3) return ventriloctl(argc, argv); // Ventrilo Ctrl |
- |
+ |
// Usage |
printf("\n"); |
printf("Usage: %s <device> [key]\n", argv[0]); |
@@ -188,7 +200,7 @@ |
printf("Running this program without 'key' specified\n"); |
printf("will run the 'FindKey' sub-program.\n"); |
printf("\n"); |
- |
+ |
// Return |
return 0; |
} |