如何通过 iTerm2 Python API 发送 "alt-s"

How to send "alt-s" via iTerm2 Python API

iTerm2PythonAPI提供了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

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).