Skip to content

Commit

Permalink
Merge pull request #162 from dylan-chong/improved-os-x
Browse files Browse the repository at this point in the history
Improved os x server (various things)
  • Loading branch information
calmofthestorm authored Jul 17, 2018
2 parents ef8ef3d + f07b6ec commit 4984f0c
Showing 1 changed file with 15 additions and 16 deletions.
31 changes: 15 additions & 16 deletions server/osx/server_osx.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@


_MOD_TRANSLATION = {
'alt': 'alt',
'alt': 'option',
'shift': 'shift',
'control': 'control',
'super': 'command',
Expand All @@ -96,15 +96,15 @@
'apostrophe': "'",
'asterisk': '*',
'at': '@',
'backslash': '\\',
'backslash': '\\\\',
'backtick': '`',
'bar': '-',
'bar': '|',
'caret': '^',
'colon': ':',
'comma': ',',
'dollar': '$',
'dot': '.',
'dquote': '"',
'dquote': '\\\"',
'equal': '=',
'exclamation': '!',
'hash': '#',
Expand All @@ -131,10 +131,10 @@

_MODIFIER_KEY_DIRECT = {
# modifiers
'command': 'command',
'win': 'command',
'shift': 'shift',
'option': 'option',
'control': 'control',
'alt': 'option',
'ctrl': 'control',
'rightshift': 'rightshift',
'rightoption': 'rightoption',
'rightcontrol': 'rightcontrol',
Expand Down Expand Up @@ -429,9 +429,6 @@ def key_press(
key_to_press = _KEYCODE_TRANSLATION.get(key.lower(), None)
command = 'key code "{0}"'.format(key_to_press)

if key_to_press is None:
raise RuntimeError("Don't know how to handle keystroke {0}".format(key))

if modifiers:
elems = map(lambda s: "%s down" % s, modifiers)
key_command = "%s using {%s} " % (command, ', '.join(elems))
Expand All @@ -456,14 +453,16 @@ def key_press(

def write_text(text, paste=False):
'''send text formatted exactly as written to active window. will use
pbpaste clipboard to paste the text instead of typing it.'''
simulate keypress typing for maximum compatibility.'''

logging.debug("text = %s paste = %s" % (text, paste))
logging.debug("text = %s" % (text))
if text:
# copy the pasted text to the clipboard
write_command(text, arguments='', executable='pbcopy')
# paste
key_press('v', 'super')
script = applescript.AppleScript('''
tell application "System Events"
keystroke "{text}"
end tell
'''.format(text=text))
script.run()


def mouseEvent(type, posx, posy, clickCount=1):
Expand Down

0 comments on commit 4984f0c

Please sign in to comment.