Я пытаюсь создать программу, которая принимает ввод клавиши с помощью pygame.joystick, а затем позволяет ей нажимать определенную клавишу, чтобы иметь больший контроль над вводом (для всех, кому интересно, это «преобразовать» поведение ключевой контроллер, который принимает Euro Truck Simulator 2).
Отчасти благодаря этому парню, я смог заставить его работать. Единственная проблема у меня с Tkinter. Когда я перетаскиваю экран, если нет кода, только controlcheck () активен, он работает нормально. Однако если я попытаюсь перетащить экран, когда активированы и controlcheck (), и startkey () (из-за нажатия «Сохранить»), экран вернется назад, как показано в этом видео.
Спасибо всем заранее за помощь, Adutchman
import pygame,sys,time
from tkinter import *
from tkinter.ttk import *
from tkinter import scrolledtext
from ahk import AHK
#Note: All commands that are commented out are for debugging
#Defines the window and AutoHotkey
ahk = AHK()
window = Tk()
window.title("Ets2 Button Admin")
window.geometry('500x300')
#initiates pygame joystick
pygame.joystick.init()
pygame.display.init()
#Defines the combobox
combo = Combobox(window)
combo.grid(column=0,row=1)
#txt = scrolledtext.ScrolledText(window,width=40,height=10)
#txt.grid(column=0, row=4)
lblconnected = False
selectedset = False
#save = False
def controlcheck():
count = pygame.joystick.get_count()
global joysticks
global lblconnected
joysticks = []
j_name = []
if count == 0:
#If there is no controller connected, it displays this message on the label:
lbl = Label(window, text="There is no controller connected to the PC, please connect a controller")
lbl.grid(column=0, row=0)
lblconnected = False
elif count > 0:
if lblconnected == False:
#creates the label only when it hasn't been created already
lbl = Label(window, text="Choose one of the connected controllers:")
lbl.grid(column=0, row=0)
lblconnected = True
for i in range( count ):
#for every controller, this for loop adds it to joysticks, initiates it and puts it in the combobox
joysticks.append( pygame.joystick.Joystick( i ) )
joysticks[i].init()
j_name.append(joysticks[i].get_name())
combo['values'] = j_name
#txt.insert(INSERT,save)
window.after(2000,controlcheck)
def startkey():
startlbl = []
global selectedset
global selected
global joysticks
if selectedset == True:
#If the user has selected a controller with the save button (see callback)
for event in pygame.event.get():
#Checks every button combination and if a button is pressed, it presses a corresponding button with AHK.
if event.type == pygame.JOYBUTTONDOWN:
if event.button == 6 and event.joy == selected:
ahk.key_press('end')
#startlbl.append("end ")
if event.button == 7 and event.joy == selected:
ahk.key_down('e')
#startlbl.append("start_press ")
if event.type == pygame.JOYBUTTONUP:
if event.button == 6 and event.joy == selected:
ahk.key_press('end')
#startlbl.append("2end ")
if event.button == 7 and event.joy == selected:
ahk.key_up('e')
#startlbl.append("start_loose")
#txt.insert(INSERT,startlbl)
window.after(18,startkey)
def callback():
#Saves the selected controller in "selected"
#global save
global selectedset
global selected
lbl = Label(window, text="Your configuration is saved")
lbl.grid(column=0, row=3)
selected = combo.current()
selectedset = True
save = True
b = Button(window, text="Save", command=callback)
b.grid(column=2,row=1)
controlcheck()
startkey()
window.mainloop()