| 1 | /** |
|---|
| 2 | * VirtualBox Ventrilo Controller (VBVC) v1.0 - Kevin M. Fitzgerald |
|---|
| 3 | * --------------------------------------------------------------------------- |
|---|
| 4 | * $Id$ - http://www.kevinfitzgerald.net |
|---|
| 5 | * $Url$ |
|---|
| 6 | * |
|---|
| 7 | * [ ABOUT ]------------------------------------------------------------------ |
|---|
| 8 | * This application listens to keystrokes typed on the running system |
|---|
| 9 | * and when the desired key is pressed (argv[2]) by listening to the |
|---|
| 10 | * /dev/input/event# device, where 'event#' is the name of your input |
|---|
| 11 | * device you want to listen on (you must have access to read from |
|---|
| 12 | * the device, e.g. use sudo run this app, or change the dev permissions |
|---|
| 13 | * with chmod [there are ways of configuring this on system start, e.g. |
|---|
| 14 | * /etc/udev/rules.d] ) |
|---|
| 15 | * |
|---|
| 16 | * [ CREDITS ]---------------------------------------------------------------- |
|---|
| 17 | * Original code by Adam Pierce - http://www.doctort.org/adam/ |
|---|
| 18 | * http://www.doctort.org/adam/nerd-notes/x11-fake-keypress-event.html |
|---|
| 19 | * |
|---|
| 20 | * Adapted code from Purkka Productions |
|---|
| 21 | * - Toni Spets <toni.spets@gmail.com> |
|---|
| 22 | * - Markus Lindqvist <markus.lindqvist@gmail.com> |
|---|
| 23 | * |
|---|
| 24 | * [ MOTIVATION ]------------------------------------------------------------- |
|---|
| 25 | * My Fiance needed a fool-proof method of getting ventrilo to work with her |
|---|
| 26 | * Ubuntu 8.04 install so she could participate in World of Warcraft raids. ;) |
|---|
| 27 | * I Love you! |
|---|
| 28 | * |
|---|
| 29 | * [ LICENSE ]---------------------------------------------------------------- |
|---|
| 30 | * Copyright (c) 2008 Soarce Technologies http://www.soarcetech.com |
|---|
| 31 | * Kevin M. Fitzgerald <kevin@kevinfitzgerald.net> |
|---|
| 32 | * + Adaption for use with VirtualBox for a reliable vent usage on linux |
|---|
| 33 | * + Dropped X bindings and functions |
|---|
| 34 | * |
|---|
| 35 | * Copyright (c) 2006 Purkka Productions |
|---|
| 36 | * Toni Spets <toni.spets@gmail.com> |
|---|
| 37 | * Markus Lindqvist <markus.lindqvist@gmail.com> |
|---|
| 38 | * + Original Ventrilo Adaption |
|---|
| 39 | * |
|---|
| 40 | * Permission to use, copy, modify, and distribute this software for any |
|---|
| 41 | * purpose with or without fee is hereby granted, provided that the above |
|---|
| 42 | * copyright notice and this permission notice appear in all copies. |
|---|
| 43 | * |
|---|
| 44 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
|---|
| 45 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
|---|
| 46 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
|---|
| 47 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
|---|
| 48 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
|---|
| 49 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
|---|
| 50 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
|---|
| 51 | */ |
|---|
| 52 | |
|---|
| 53 | #include <stdio.h> |
|---|
| 54 | #include <stdlib.h> |
|---|
| 55 | #include <string.h> |
|---|
| 56 | #include <unistd.h> |
|---|
| 57 | #include <linux/input.h> |
|---|
| 58 | #include <fcntl.h> |
|---|
| 59 | |
|---|
| 60 | // Constant for version |
|---|
| 61 | #define VERSION "1.0" |
|---|
| 62 | |
|---|
| 63 | // Commands to execute for transmission and release |
|---|
| 64 | #define TRANSMIT_COMMAND "./vboxtransmit.sh transmit" |
|---|
| 65 | #define COMPLETE_COMMAND "./vboxtransmit.sh complete" |
|---|
| 66 | |
|---|
| 67 | int main(int argc, char **argv) |
|---|
| 68 | { |
|---|
| 69 | // |
|---|
| 70 | // Verify usage |
|---|
| 71 | // |
|---|
| 72 | |
|---|
| 73 | if (argc < 3) |
|---|
| 74 | { |
|---|
| 75 | printf("usage: %s <device> <listen key>\n", argv[0]); |
|---|
| 76 | return 1; |
|---|
| 77 | } |
|---|
| 78 | |
|---|
| 79 | // |
|---|
| 80 | // Dump header |
|---|
| 81 | // |
|---|
| 82 | |
|---|
| 83 | printf("VirtualBox Ventrilo Controller %s\n", VERSION); |
|---|
| 84 | printf("$Id$\n"); |
|---|
| 85 | printf("==================================================================\n"); |
|---|
| 86 | printf("CAREFUL: This program reads your keyboard DIRECTLY just like how a\n"); |
|---|
| 87 | printf(" keylogger would. You need correct permissions to read the\n"); |
|---|
| 88 | printf(" event device.\n"); |
|---|
| 89 | |
|---|
| 90 | |
|---|
| 91 | // |
|---|
| 92 | // Initialize |
|---|
| 93 | // |
|---|
| 94 | |
|---|
| 95 | printf("Initializing..."); |
|---|
| 96 | |
|---|
| 97 | // Open event device |
|---|
| 98 | int fd; |
|---|
| 99 | fd = open(argv[1], O_RDONLY); |
|---|
| 100 | if(!fd) |
|---|
| 101 | { |
|---|
| 102 | printf("Error: Can't opening device %s\n", argv[1]); |
|---|
| 103 | return 1; |
|---|
| 104 | } |
|---|
| 105 | |
|---|
| 106 | struct input_event ev; |
|---|
| 107 | |
|---|
| 108 | printf ("Done.\nMake sure to set Ventrilo to listen for the LEFT-SHIFT key! (default)\n"); |
|---|
| 109 | printf ("\nUse CTRL-C to quit.\n"); |
|---|
| 110 | |
|---|
| 111 | |
|---|
| 112 | // |
|---|
| 113 | // Key listener |
|---|
| 114 | // |
|---|
| 115 | |
|---|
| 116 | while(1) |
|---|
| 117 | { |
|---|
| 118 | // Read keystroke |
|---|
| 119 | read(fd, &ev, sizeof(struct input_event)); |
|---|
| 120 | if(ev.type == 1) |
|---|
| 121 | { |
|---|
| 122 | if(ev.code == atoi(argv[2])) |
|---|
| 123 | { |
|---|
| 124 | if(ev.value == 1) |
|---|
| 125 | { |
|---|
| 126 | // Send press event |
|---|
| 127 | printf("Transmitting..."); fflush(stdout); |
|---|
| 128 | system(TRANSMIT_COMMAND); |
|---|
| 129 | } |
|---|
| 130 | else if(!ev.value) |
|---|
| 131 | { |
|---|
| 132 | // Send release event |
|---|
| 133 | printf("Done.\n"); |
|---|
| 134 | system(COMPLETE_COMMAND); |
|---|
| 135 | } |
|---|
| 136 | } |
|---|
| 137 | } |
|---|
| 138 | } |
|---|
| 139 | |
|---|
| 140 | // Unreachable code, No CTRL+C handler present |
|---|
| 141 | printf("Finished. Goodbye!\n\n"); |
|---|
| 142 | return 0; |
|---|
| 143 | } |
|---|