Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- import subprocess, time
- key_press_delay_ms = 12
- character_mapping = [
- { "char":'\n', "mapped": 'Return' },
- { "char":'-', "mapped": 'minus'},
- { "char":'[', "mapped": 'bracketleft'},
- { "char":']', "mapped": 'bracketright'},
- { "char":'{', "mapped": 'braceleft'},
- { "char":'}', "mapped": 'braceright'},
- { "char":'\"', "mapped": 'quotedbl'},
- { "char":'&', "mapped": 'ampersand'},
- { "char":'/', "mapped": 'slash'},
- { "char":'\`', "mapped": 'grave'},
- { "char":'$', "mapped": 'dollar'},
- { "char":'\'', "mapped": 'apostrophe'},
- ]
- def flushTyping( arguements ):
- #print("Typing:\n" + arguements )
- time.sleep( key_press_delay_ms * 1.0 / 1000 )
- command = ["xdotool", "type", "--clearmodifiers", "--delay", str( key_press_delay_ms ), str( arguements )]
- subprocess.call(command)
- def flushKeypress( arguements ):
- #print("Keypress:\n" + arguements)
- time.sleep( key_press_delay_ms * 1.0 / 1000 )
- arguements = arguements.strip().split(" ")
- #print ["xdotool", "type", "--clearmodifiers", "--delay", key_press_delay_ms ] + arguements
- command = ["xdotool", "key", "--clearmodifiers", "--delay", str( key_press_delay_ms )] + arguements
- subprocess.call( command )
- if __name__ == "__main__":
- import pyperclip
- contents = pyperclip.getcb()
- keypress_arguements = ""
- typing_arguements = ""
- last_addition = "typing"
- character_checklist = []
- for item in character_mapping:
- character_checklist.append( item["char"] )
- for character in contents:
- if character in character_checklist:
- for item in character_mapping:
- if item["char"] == character:
- keypress_arguements += " " + item["mapped"]
- break
- if last_addition == 'typing':
- flushTyping( typing_arguements )
- typing_arguements = ""
- last_addition = 'keypress'
- else:
- typing_arguements += character
- if last_addition == 'keypress':
- flushKeypress( keypress_arguements )
- keypress_arguements = ""
- last_addition = 'typing'
- if last_addition == "typing":
- flushTyping( typing_arguements )
- else:
- flushKeypress( keypress_arguements )
Advertisement
Add Comment
Please, Sign In to add comment