简体   繁体   English

Alt 和 Ctrl 键不适用于 keyboard.is_pressed

[英]Alt and Ctrl keys not working with keyboard.is_pressed

So simply, I was trying to create a code that when you press certain buttons, it writes out whatever you put into the Tk input.很简单,我试图创建一个代码,当您按下某些按钮时,它会写出您放入 Tk 输入的任何内容。 I was trying to make a hotkey with alt and another letter but whenever I use alt or ctrl, the function does not work and opens up random applications on my screen.我试图用 alt 和另一个字母制作热键,但每当我使用 alt 或 ctrl 时,function 不起作用并在我的屏幕上打开随机应用程序。 everything works fine with keys like shift + a for example, but outputs it all in capitals because of the use of shift.例如,使用 shift + a 之类的键一切正常,但由于使用了 shift,所以将其全部输出为大写字母。 The part where I write the Hotkeys is where all the Hotkey variables are我编写热键的部分是所有热键变量的位置

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

From the docs , it looks like it should be:docs看来,它应该是:

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

without the spaces没有空格

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM