Skip to content

Commit

Permalink
more send methods
Browse files Browse the repository at this point in the history
  • Loading branch information
spyoungtech committed Mar 4, 2019
1 parent f89c489 commit 37fba50
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 14 deletions.
20 changes: 11 additions & 9 deletions ahk/keyboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,33 +63,35 @@ def key_wait(self, key, timeout: float=None, logical_state=False, pressed=None,
script = self.render_template('keyboard/key_wait.ahk', key, timeout, options)
return self.run_script(script)

def write(self, s):
def type(self, s):
"""
Sends keystrokes using send_input, also escaping the string for use in AHK.
"""
s = escape_sequence_replace(s)
self.send_input(s)

def send(self, s, delay=None):
script = self.render_template('keyboard/send.ahk', s=s, delay=delay)
def send(self, s, raw=False, delay=None):
script = self.render_template('keyboard/send.ahk', s=s, raw=raw, delay=delay)
return self.run_script(script)

def send_raw(self, s):
raise NotImplementedError
def send_raw(self, s, delay=None):
return self.send(s, raw=True, delay=delay)

def send_input(self, s):
if len(s) > 5000:
warnings.warn('String length greater than allowed. Characters beyond 5000 may not be sent. '
'See https://autohotkey.com/docs/commands/Send.htm#SendInputDetail for details.')

script = self.render_template('keyboard/send_input.ahk', s=s)
return self.run_script(script)
self.run_script(script)

def send_play(self, s):
raise NotImplementedError
script = self.render_template('keyboard/send_play.ahk', s=s)
self.run_script(script)

def send_event(self, s):
raise NotImplementedError
def send_event(self, s, delay=None):
script = self.render_template('keyboard/send_event.ahk', s=s, delay=delay)
self.run_script(script)

def key_press(self, key, release=True):
"""
Expand Down
2 changes: 1 addition & 1 deletion ahk/templates/keyboard/send.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
{% block body %}
{% if delay %}SetKeyDelay, {{ delay }}{% endif %}

Send {{ s }}
Send{% if raw %}Raw{% endif %} {{ s }}
{% endblock body %}
6 changes: 6 additions & 0 deletions ahk/templates/keyboard/send_event.ahk
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{% extends "base.ahk" %}
{% block body %}
{% if delay %}SetKeyDelay, {{ delay }}{% endif %}

SendEvent {{ s }}
{% endblock body %}
6 changes: 6 additions & 0 deletions ahk/templates/keyboard/send_play.ahk
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{% extends "base.ahk" %}
{% block body %}
{% if delay %}SetKeyDelay, {{ delay }}{% endif %}

SendPlay {{ s }}
{% endblock body %}
6 changes: 2 additions & 4 deletions ahk/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,6 @@ def send(self, raw=False):
raise NotImplementedError




class Window(object):
_subcommands = {
'id': 'ID',
Expand Down Expand Up @@ -261,13 +259,13 @@ def move(self, x='', y='', width=None, height=None):
script = self._render_template('window/win_move.ahk', x=x, y=y, width=width, height=height)
self.engine.run_script(script)

def send(self, keys, delay=None, raw=False, blocking=False):
def send(self, keys, delay=None, raw=False, blocking=False, escape=True):
"""
Send keystrokes directly to the window.
Uses ControlSend
https://autohotkey.com/docs/commands/Send.htm
"""
if not raw:
if escape:
keys = escape_sequence_replace(keys)
script = self._render_template('window/win_send.ahk', keys=keys, raw=raw, delay=delay, blocking=blocking)
return self.engine.run_script(script, blocking=blocking)
Expand Down

0 comments on commit 37fba50

Please sign in to comment.