Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /usr/bin/env python
- # dependancy: https://launchpad.net/python-uinput/
- # http://i.imgur.com/KwU6s.png
- import uinput
- from time import sleep
- class Keyboard:
- """Creates a virtual keyboard which can emulate a real keyboard"""
- def __init__(self, cs):
- self.events = dict((i, self.c2key(i)) for i in cs)
- self.keyboard = uinput.Device(tuple(self.events.values()))
- # There is a delay before the keyboard starts working
- # At an order of magnitude of -2
- sleep(1e-1)
- def c2key(self, c):
- return eval('uinput.KEY_' + c.upper())
- def press(self, c):
- self.keyboard.emit(self.events[c], 1)
- def release(self, c):
- self.keyboard.emit(self.events[c], 0)
- def qwop():
- keyboard = Keyboard(["q", "w", "o", "p"])
- while 1:
- keyboard.press("w") # Press 'W'
- sleep(1e-1) # Wait 100 ms
- keyboard.press("o") # Press 'O'
- sleep(1e-1) # Wait 100 ms
- keyboard.release("o") # Release 'O'
- keyboard.release("w") # Release 'W'
- sleep(1e-1) # Wait 100 ms
- keyboard.press("q") # Press 'Q'
- keyboard.release("p") # Release 'P'
- sleep(2e-1) # Wait 200 ms
- keyboard.press("p") # Press 'P'
- keyboard.release("q") # Release 'Q'
- sleep(1e-1) # Wait 100 ms
- keyboard.release("p") # Release 'P'
- keyboard.press("p") # Press 'P'
- sleep(1e-1) # Wait 100 ms
- if __name__ == '__main__':
- qwop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement