SHARE
TWEET

AutoTyping

rynagade Apr 25th, 2013 38 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import win32com.client as comclt
  2. import win32gui
  3. import datetime
  4. import time
  5. import random
  6.  
  7. wsh = comclt.Dispatch("WScript.Shell")
  8. p1 = "Xaviera Kirby was keying a computer program when she realized she kept making the mistake of keying a \ for a /.  The symbol / is called the diagonal, the slash, or occasionally, the virgule.  Xaviera didn't know that she could always use the diagonal, /, between two words to indicate that the meaning of either word pertains; i.e., and/or.  In addition, the slash could be used as a dividing line in dates or fractions; i.e., 4/23/94 or 1/6.  The virgule, /, is also used as the division symbol in almost all programming languages and in particular mathematical applications."
  9. p2 = "You will learn in class that computer software directs the hardware to do its work in the proper way.  You may already know about a common type of software, a word processor.  Other kinds include database, spreadsheet, desktop publishing, and graphics.  Often these are included in one integrated package that is sold at a very reasonable price.  Software costs are most likely based on the quality and quantity of work that the software will allow a personal computer to do.  It's very important that your hardware have enough memory to run the software that you want to use."
  10.  
  11.  
  12. class KeyChamp(object):
  13.     pass
  14.  
  15.     def checkActive(self):
  16.         if win32gui.GetForegroundWindow() == self.npad:
  17.             return True
  18.         else:
  19.             raise Exception('Program has to be active!')
  20.  
  21.     def timer(self):
  22.         current = datetime.datetime.now()
  23.         elapsed = current - self.start
  24.         if elapsed > datetime.timedelta(seconds=300):
  25.             raise Exception('Time is up!')
  26.        
  27.     def specialKeys(self, key):
  28.         if key == '%':
  29.             wsh.SendKeys("{%}")
  30.         elif key == '^':
  31.             wsh.SendKeys("{^}")
  32.         elif key == '+':
  33.             wsh.SendKeys("{+}")
  34.         elif key == '~':
  35.             wsh.SendKeys("{~}")
  36.  
  37.     def typing(self):
  38.         wsh.AppActivate("Keychamp 2.0") # select the application
  39.         self.npad = win32gui.GetForegroundWindow()
  40.         self.start = datetime.datetime.now()
  41.         while True:
  42.             wsh.SendKeys("{Tab}")
  43.             for i in p1:
  44.                 if i == '%' or i == '^' or i == '+' or i == '~':
  45.                     self.specialKeys(i)
  46.                 elif self.checkActive() != True:
  47.                     exit
  48.                 else:
  49.                     wsh.SendKeys(i) # send the keys you want
  50.                     time.sleep(random.uniform(0.200, 0.210))
  51.                 self.timer()
  52.             wsh.SendKeys("{Enter}")
  53.             wsh.SendKeys("{Tab}")
  54.             for i in p2:
  55.                 if i == '%' or i == '^' or i == '+' or i == '~':
  56.                     self.specialKeys(i)
  57.                 elif self.checkActive() != True:
  58.                     exit
  59.                 else:
  60.                     wsh.SendKeys(i) # send the keys you want
  61.                     time.sleep(random.uniform(0.200, 0.210))
  62.                 self.timer()
  63.             wsh.SendKeys("{Enter}")
  64.  
  65. k = KeyChamp()
  66. k.typing()
RAW Paste Data
Top