Advertisement
saurabhmesh17

Script to convert getevnet to sendevent

Sep 2nd, 2014
4,784
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.67 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # coding: utf-8
  3.  
  4. # From hex_to_dec.py (which I created a while ago)
  5.  
  6. # Tweaking for Mac
  7. #
  8. # Fixed indenting that wordpress was breaking
  9. #
  10. # You need python installed – more info here:
  11. # Python – http://www.python.org/download/
  12. # The Purpose of this script
  13. #
  14. # Script name: hex_to_dec.py
  15. #
  16. # To turn the getevent output from this:
  17. # /dev/input/event0: 0003 0001 00000092
  18. # to this (something can be run)
  19. # sendevent /dev/input/event0 3 1 92
  20. # Outfile of what to do
  21. # List input file on command line when running
  22. # Open file
  23. # prefix “adb shell sendevent” command to line
  24. # remove colon from input
  25. # convert 3 hexidecimal values to decimal values
  26. # Assemble new complete line
  27. # write out line to new file,
  28. # named the original filename +suffix “bat” – windows batch file ready to run
  29. #
  30.  
  31. # Importing Stuff
  32. import sys
  33. import fileinput
  34. import struct
  35. ###################################################################################################
  36. #
  37. # Variables
  38. #
  39.  
  40. # Command prefix
  41. prefix = "sendevent "
  42.  
  43. inputline = ""
  44. complete = ""
  45. part1len = 0
  46. part1 = ""
  47. part2 = ""
  48.  
  49. num1 = 0
  50. num2 = 0
  51. num3 = 0
  52.  
  53. # File stuff
  54. rawfile = ""
  55. outfile = ""
  56. filename = ""
  57. ###################################################################################################
  58. #
  59. # File operations
  60. #
  61.  
  62. # Grabs the file name from the command line when you run the python script
  63. rawfile = sys.argv[-1]
  64.  
  65. # Open the input file
  66. # r – Opens a file for reading only. The file pointer is placed at the beginning of the file. This is the default mode.
  67. # w – Opens a file for writing only. Overwrites the file if the file exists. If the file does not exist, creates a new file for writing.
  68. #
  69. fo = open(rawfile, "r")
  70.  
  71. # Create output file, taking everything in front of the . (kind of windows centric)
  72. filename = rawfile.find(".");
  73. outfile = rawfile[:filename] + ".scr"
  74.  
  75. # Output file
  76. fw = open(outfile, "w")
  77.  
  78. # Stuff at the top of the script (first commands to run)
  79. # Puts into bash
  80. fw.write("#!/bin/sh\n")
  81.  
  82. # User Message
  83. fw.write("echoing – drawing function " + "\n")
  84.  
  85. ###################################################################################################
  86. #
  87. # Process input string, creating new formatted command
  88. #
  89. for inputline in fo.read().split("\n"):
  90.     # Used for testing/debug
  91.     # print inputline
  92.     # Otherwise let"s process the line
  93.     # Find the location of the colon
  94.     part1len = inputline.find(":");
  95.  
  96.     # -1 means end of file so quit processing
  97.     if part1len > -1:
  98.         # Only take the first part of the string up to the string
  99.         part1 = inputline[:part1len];
  100.  
  101.         # Finding the hexidecimal values
  102.         # Splits the string based on spaces, creating an array with 4 strings,
  103.         part2 = inputline.split(" ");
  104.  
  105.         # we want strings 1,2,3 (since arrays start at 0 (zero))
  106.         # we need to specify the base explicitly (based 16, so hex gets converted to decimal)
  107.  
  108.         print part2[1]
  109.         print part2[2]
  110.         print part2[3]
  111.  
  112.         num1 = int(part2[1], 16)
  113.         num2 = int(part2[2], 16)
  114.         num3 = int(part2[3], 16)
  115.  
  116.         # Put is all together
  117.         complete = prefix + part1 + " " + str(num1) + " " + str(num2) + " " + str(num3)
  118.  
  119.         # Write out to the file, with a new line feed
  120.         fw.write(complete + "\n")
  121. # For testing
  122. # Print complete
  123.  
  124. # Info for the user
  125. print "Processing complete"
  126. print "File created: ", outfile
  127. print
  128. print "Copy file to the device"
  129. print "adb push " + outfile + " /sdcard/" + outfile
  130. print
  131. print "Run the script"
  132. print "adb shell sh /sdcard/" + outfile
  133. ###################################################################################################
  134. #
  135. # File clean up
  136. #
  137.  
  138. # Close all files
  139. fo.close()
  140. fw.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement