如何通过iTerm2 Python API发送“alts”

2024-05-17 13:55:43 发布

您现在位置:Python中文网/ 问答频道 /正文

iTerm2 Python API提供接受字符串的异步发送文本。我可以将“s”字符作为输入发送到当前会话,但我想知道如何模拟按键盘上的“alt-s”。以下是我目前掌握的情况:

#!/usr/bin/env python3.7

import iterm2

async def main(connection):
    app = await iterm2.async_get_app(connection)
    s = app.current_terminal_window.current_tab.current_session
    await s.async_send_text('s')


iterm2.run_until_complete(main)

Tags: 字符串文本apiappasyncmain情况current
1条回答
网友
1楼 · 发布于 2024-05-17 13:55:43

当前API不接受带有类似ALT.Fromhttps://gitlab.com/gnachman/iterm2/-/issues/8387的修饰符的按键行程

Most of the time it's better to use an API call if one is available instead of sending a keystroke, since keystrokes only work some of the time (e.g., if keyboard focus is in the prefs panel then Cmd-D won't do anything).

相关问题 更多 >