如何检测pythoncurses中的快捷键组合CTRL + Key

问题描述 投票:0回答:1

我一直在阅读有关Python中的curses的文档,但我不知道如何检测诸如CTRL-S、CTRL-A、ALT-X或CMD+A(在macOS中)等组合。 有谁知道怎么做吗?

有人提到了用户ord(),但我找不到CTRL返回的数字。

提前致谢

python curses python-curses
1个回答
0
投票

windows.getkey
对于 CTRL-A 返回
^A
,对于 CTRL-S 返回
^S
,等等

尝试查看按下某个键时

getkey
返回的字符串:

from curses import wrapper

def main(stdscr):
    # Clear screen
    stdscr.clear()

    while True:
        key = stdscr.getkey()
        stdscr.addstr(0,0, "Key pressed is '{}'".format(key))
        stdscr.refresh()

wrapper(main)
© www.soinside.com 2019 - 2024. All rights reserved.