![](/img/trans.png)
[英]How to replace the Python logo in a Tkinter-based Python GUI app?
[英]Hotkeys in a minimized Tkinter-based program
我正在為游戲制作 hack,我想在游戲全屏運行時使用 F7 熱鍵啟動/停止腳本。 我曾嘗試使用root.bind
和pynput
來做到這一點,但它們都沒有奏效。
這是我的代碼:
hack_running = False
def hack():
if hack_running:
PressKeyPynput(0x02)
time.sleep(0.08)
ReleaseKeyPynput(0x02)
PressKeyPynput(0x11)
time.sleep(0.5)
ReleaseKeyPynput(0x11)
PressKeyPynput(0x1F)
time.sleep(0.6)
ReleaseKeyPynput(0x1F)
PressKeyPynput(0x02)
time.sleep(0.08)
ReleaseKeyPynput(0x02)
root.after(900000, hack)
def Start_stop():
global hack_running
if Startk['text'] == 'Start':
hack_running = True
hack()
Startk.config(text='Stop')
else:
hack_running = False
Startk.config(text='Start')
root = tk.Tk()
root.resizable(False, False)
canvas = tk.Canvas(root, height=HEIGHT, width=WIDTH)
canvas.pack()
frame = tk.Frame(root, bg='black')
frame.place(relwidth=1, relheight=1)
Startk = tk.Button(frame, text='Start', font=("Calibri", 10), command=Start_stop)
Startk.pack(side='top', pady='50')
root.mainloop()
嘗試使用 pynput:
import pynput
def run():
print('f7') # your code
def press(key):
if key == pynput.keyboard.Key.f7:
run()
pynput.keyboard.Listener(on_press=press).run()
有關鍵盤組合,請參閱此 github 問題。 希望這會有所幫助!
Pynput 有一個簡單的 class ,它提供名為 GlobalHotKeys 的熱鍵GlobalHotKeys
。 參考這里。
不幸的是,如果只有 python,我想如果你想讓它在游戲中工作,它就不能做更多了。
通常游戲中也有鍵盤監聽線程。當你的python腳本和你的游戲一起工作時,它們會產生沖突。而你的python腳本不能正常工作。(並且游戲總是會采取一些措施來防止作弊。)
據我所知, AutoHotkey
腳本可以在游戲中運行(至少它在過去對我有用)。 AutoHotkey 官方文檔。在macOS
,參考這個
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.