很简单,我试图创建一个代码,当您按下某些按钮时,它会写出您输入 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()
答案 0 :(得分:1)