gpt4 book ai didi

python - 这个 autokey Python 脚本需要并发吗?

转载 作者:太空宇宙 更新时间:2023-11-04 06:22:47 26 4
gpt4 key购买 nike

我最近切换到 Ubuntu,我想念 autohotkey。我正在使用 autokey重新创建我的热键环境。我重新映射了 CapsLockF13使用 Xmodmap .

我需要做的: 当F13被点击,返回<Esc> . 当F13与键一起使用,触发热键。 当F13按住 1 秒以上,无热键释放,不返回任何内容。

Autokey 使用 Python 环境。这是我的计划:

    F13 is pressed
Start a timer
Start a thread listening for <CapsLock up> and if true,
if timer is less than 1 second && no hotkey was pressed
exit script after returning <Esc>
exit script


Start a thread that loops forever
Listen for hotkey
Play hotkey's function

脚本在 CapsLock 时结束发行了。

示例:我按 CapsLock然后j输出是Down arrow .

我在开始编码之前的问题是,我真的需要为此使用多线程(并发)吗?这是最好的方法吗?我觉得有一种更简单的方法,而且我也从未使用并发编码。

编辑:我愿意接受任何方法来实现这一点,即使它不是使用 autokey 或 python。

最佳答案

在这种情况下你绝对不需要使用线程。你可以做这样的事情:

F13 is pressed
Start timer
While True:
Listen for hotkey and capslock up
if capslock up:
if timer < 1:
return <Esc> and exit
else: just exit
elif hotkey:
Execute hotkey function and exit

我们退出的唯一两种方式是释放大写锁定或按下热键,这两种方式中只有一种是我们需要担心的事件,因此我们可以在同一个线程中监听这两种方式。

关于python - 这个 autokey Python 脚本需要并发吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10777796/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com