iTerm2 Python API提供了async_send_text,它接受一个字符串。我可以将“ 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)
当前的API不接受带有ALT等修饰键的击键。来自https://gitlab.com/gnachman/iterm2/-/issues/8387
在大多数情况下,如果可以使用API调用而不是发送击键,最好使用API调用,因为击键仅在某些时间起作用(例如,如果键盘焦点位于首选项面板中,则Cmd-D不会执行任何东西)。