1 Star 4 Fork 3

Roa-Haskel/share_controller

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
key_event_factory.py 1.39 KB
一键复制 编辑 原始数据 按行查看 历史
Roa-Haskel 提交于 2022-10-31 00:29 . zhushi
from pynput.keyboard import Key,KeyCode
import sys
keyChars = r"1!2@3#4$5%6^7&8*9(0)-_=+[{]}\|/?,<.>".strip()
_keyChars = {keyChars[i]: keyChars[i + 1] for i in range(0, len(keyChars), 2)}
class KeyEventFactory:
keyChars=_keyChars
keyNames="""
cmd:alt
alt_l:cmd
""".strip().split("\n")
keyNames={i.split(":")[0]:i.split(":")[1] for i in keyNames}
# keyChars={i[0]:i[1] for i in keyChars}
def __init__(self):
self.shiftRelease=True
def input(self,key):
if 'name' in dir(key):
if 'shift' in key.name:
self.shiftRelease=not self.shiftRelease
data=("name",key.name)
elif 'char' in dir(key) and key.char is not None:
keyChar=key.char
if not self.shiftRelease:
keyChar=self.keyChars.get(keyChar,keyChar)
data=("char",keyChar)
else:
data=("vk",key.vk)
return data
def outPut(self,data):
tp,dt=data
if tp=="name":
if sys.platform == 'darwin':
name=self.keyNames.get(dt,dt)
else:
name=dt
try:
key=Key[name]
except:
key=None
elif tp=='char':
key=dt
elif tp=='vk':
key=KeyCode.from_vk(dt)
else:
raise TypeError(str(data))
return key
if __name__ == '__main__':
pass
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/Roa-Haskel/share_controller.git
[email protected]:Roa-Haskel/share_controller.git
Roa-Haskel
share_controller
share_controller
master

搜索帮助