Guest User

Untitled

a guest
Sep 20th, 2015
104
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "plugin.h"
  2.  
  3. #define DEFAULT_DELAY 10
  4.  
  5. enum plugin_status plugin_start(const void *param)
  6. {
  7. if(!param)
  8. rb->splash(2*HZ, "Execute a USBScript file!");
  9. const char *path = (const char*) param;
  10. int fd = rb->open(path, O_RDONLY);
  11.  
  12. int line = 0;
  13.  
  14. int default_delay = DEFAULT_DELAY;
  15.  
  16. while(1)
  17. {
  18. char instr_buf[256];
  19. if(rb->read_line(fd, instr_buf, sizeof(instr_buf)) == 0)
  20. return PLUGIN_OK;
  21. ++line;
  22.  
  23. char *tok = NULL, *save = NULL;
  24.  
  25. /* execute all the commands on this line/instruction */
  26. do {
  27. tok = rb->strtok_r(instr_buf, " ", &save);
  28.  
  29. if(rb->strcmp(tok, "GUI") == 0) {
  30. rb->usb_hid_send(HID_USAGE_PAGE_KEYBOARD_KEYPAD, HID_KEYBOARD_LEFT_GUI);
  31. }
  32. else if(rb->strcmp(tok, "RGUI") == 0) {
  33. rb->usb_hid_send(HID_USAGE_PAGE_KEYBOARD_KEYPAD, HID_KEYBOARD_RIGHT_GUI);
  34. }
  35. else if(rb->strcmp(tok, "DELAY") == 0) {
  36. /* delay N 100ths of a sec */
  37. tok = rb->strtok_r(instr_buf, " ", &save);
  38. rb->sleep((HZ / 100) * rb->atoi(tok));
  39. }
  40. else if(rb->strcmp(tok, "CONTROL") == 0) {
  41. rb->usb_hid_send(HID_USAGE_PAGE_KEYBOARD_KEYPAD, HID_KEYBOARD_LEFT_CONTROL);
  42. }
  43. else if(rb->strcmp(tok, "ESCAPE") == 0) {
  44. rb->usb_hid_send(HID_USAGE_PAGE_KEYBOARD_KEYPAD, HID_KEYBOARD_ESCAPE);
  45. }
  46. else if(rb->strcmp(tok, "RCTRL") == 0) {
  47. rb->usb_hid_send(HID_USAGE_PAGE_KEYBOARD_KEYPAD, HID_KEYBOARD_RIGHT_CONTROL);
  48. }
  49. else if(rb->strcmp(tok, "ALT") == 0) {
  50. rb->usb_hid_send(HID_USAGE_PAGE_KEYBOARD_KEYPAD, HID_KEYBOARD_LEFT_ALT);
  51. }
  52. else if(rb->strcmp(tok, "RALT") == 0) {
  53. rb->usb_hid_send(HID_USAGE_PAGE_KEYBOARD_KEYPAD, HID_KEYBOARD_RIGHT_ALT);
  54. }
  55. else if(rb->strcmp(tok, "DEFAULT_DELAY") == 0) {
  56. /* sets time between instructions, 100ths of a second */
  57. tok = rb->strtok_r(instr_buf, " ", &save);
  58. default_delay = rb->atoi(tok) * (HZ / 100);
  59. }
  60. else if(rb->strcmp(tok, "REM") == 0) {
  61. break;
  62. }
  63.  
  64. rb->sleep(default_delay);
  65. } while(tok);
  66. }
  67. }
RAW Paste Data