Alt和Ctrl键不适用于键盘.已按下



简单地说,我试图创建一个代码,当你按下某些按钮时,它会写出你输入到Tk中的任何内容。我试图用alt和另一个字母制作一个热键,但每当我使用alt或ctrl时,该功能都不起作用,并在屏幕上打开随机应用程序。例如,使用shift+a这样的键,一切都很好,但由于使用了shift,所以都以大写字母输出。我编写热键的部分是所有热键变量都是

from tkinter import *
import keyboard, pyautogui
import os
import sys
import tkinter.messagebox
import time
root = Tk()
root.resizable(False, False)
root.iconbitmap('Logo.ico')
root.title(" ")
root.geometry("170x300")
Canvas(root, width=170, height=300)
hotkey1 = "alt + q"
hotkey2 = "alt + w"
hotkey3 = "alt + e"
hotkey4 = "alt + r"
Label(root, text="MacMaker").place(x = 50)
Label(root, text="Type in Macros below:").place(x = 27, y = 21)
Label(root, text="F4:").place(x = 5, y = 48)
Label(root, text="F7:").place(x = 5, y = 78)
Label(root, text="F8:").place(x = 5, y = 108)
Label(root, text="F9:").place(x = 5, y = 138)
thing1 = Entry(width=20)
thing1.place(x = 35, y = 50)
thing2 = Entry(width=20)
thing2.place(x = 35, y = 80)
thing3 = Entry(width=20)
thing3.place(x = 35, y = 110)
thing4 = Entry(width=20)
thing4.place(x = 35, y = 140)

def my_mainloop():
macro1 = thing1.get()
macro2 = thing2.get()
macro3 = thing3.get()
macro4 = thing4.get()
if keyboard.is_pressed(hotkey1):
pyautogui.typewrite(macro1)
elif keyboard.is_pressed(hotkey2):
pyautogui.typewrite(macro2)
elif keyboard.is_pressed(hotkey3):
pyautogui.typewrite(macro3)
elif keyboard.is_pressed(hotkey4):
pyautogui.typewrite(macro4)
root.after(1, my_mainloop)  
root.after(1, my_mainloop)
root.mainloop()

从文档来看,它应该是:

hotkey1 = "alt+q"
hotkey2 = "alt+w"
hotkey3 = "alt+e"
hotkey4 = "alt+r"

没有空格

最新更新