Skip to content

Commit

Permalink
Merge pull request #329 from spyoungtech/gh-328
Browse files Browse the repository at this point in the history
Ensure correct encoding for hotkeys scripts
  • Loading branch information
spyoungtech committed Jul 9, 2024
2 parents 86d9e56 + f106497 commit 6f6f0e1
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
4 changes: 3 additions & 1 deletion ahk/_hotkey.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,9 @@ def _render_hotkey_template(self) -> str:
def listener(self) -> None:
hotkey_script_contents = self._render_hotkey_template()
logging.debug('hotkey script contents:\n%s', hotkey_script_contents)
with tempfile.NamedTemporaryFile(mode='w', prefix='python-ahk-hotkeys-', suffix='.ahk', delete=False) as f:
with tempfile.NamedTemporaryFile(
mode='w', prefix='python-ahk-hotkeys-', suffix='.ahk', delete=False, encoding='utf-8'
) as f:
f.write(hotkey_script_contents)
atexit.register(try_remove, f.name)
self._proc = subprocess.Popen(
Expand Down
11 changes: 11 additions & 0 deletions tests/_async/test_keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,17 @@ async def test_hotstring(self):

assert 'by the way' in await self.win.get_text()

async def test_hotstring_cyrillic(self):
# https://github.com/spyoungtech/ahk/issues/328
self.ahk.add_hotstring('тест', 'hello world')
self.ahk.start_hotkeys()
await self.ahk.set_send_level(1)
await self.win.activate()
await self.ahk.send('тест ')
time.sleep(2)

assert 'hello world' in await self.win.get_text()

async def test_remove_hotstring(self):
self.ahk.add_hotstring('btw', 'by the way')
self.ahk.start_hotkeys()
Expand Down
10 changes: 10 additions & 0 deletions tests/_sync/test_keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,16 @@ def test_hotstring(self):

assert 'by the way' in self.win.get_text()

def test_hotstring_cyrillic(self):
self.ahk.add_hotstring('тест', 'hello world')
self.ahk.start_hotkeys()
self.ahk.set_send_level(1)
self.win.activate()
self.ahk.send('тест ')
time.sleep(2)

assert 'hello world' in self.win.get_text()

def test_remove_hotstring(self):
self.ahk.add_hotstring('btw', 'by the way')
self.ahk.start_hotkeys()
Expand Down

0 comments on commit 6f6f0e1

Please sign in to comment.