実現したいこと
・開始ボタンを押すとフリーズして落ちるのを直したい
該当のソースコード
python
1import time 2import win32api 3import keyboard 4import PySimpleGUI as sg 5import json 6 7f = open("setting.json","r") 8json_dict = json.load(f) 9horizon = json_dict["horizon"] 10vert = json_dict["vert"] 11rate = json_dict["rate"] 12 13sg.theme('DarkAmber') 14layout = [ [sg.Text('横反動'), sg.InputText(key="HORIZON",default_text=horizon)], 15 [sg.Text('縦反動'), sg.InputText(key="VERTICAL",default_text=vert)], 16 [sg.Text('レート'), sg.InputText(key="RATE",default_text=rate)], 17 [sg.Button("開始"), sg.Button("停止"), sg.Button("終了")],] 18window = sg.Window('AntiRecoil', layout) 19f.close() 20mode = 1 21key = 0 22while True: 23 event, values = window.read() 24 if event == "開始" and mode != 0: 25 key = 0 26 mode = 0 27 toggle_button = "p" 28 offset_const = 1000 29 enabled = False 30 horizontal = values["HORIZON"] 31 vertical = values["VERTICAL"] 32 firerate = values["RATE"] 33 with open('setting.json', 'r') as f2: 34 data = f2.read() 35 data = data.replace(f"{horizon}",horizontal).replace(f"{vert}",vertical).replace(f"{rate}",firerate) 36 with open('setting.json', 'w') as f2: 37 f2.write(data) 38 print("Anti-recoil script started!") 39 def is_mouse_down(): 40 lmb_state = win32api.GetKeyState(0x01) 41 return lmb_state < 0 42 firerate = float(firerate) 43 horizontal = int(horizontal) 44 vertical = int(vertical) 45 horizontal2 = 0-horizontal 46 vertical2 = 0-vertical 47 if event == "停止" and mode != 1: 48 mode = 1 49 print("Anti-recoil script stopped!") 50 if event == sg.WIN_CLOSED or event == "終了": 51 mode = 2 52 if mode == 2: 53 print("Anti-recoil script ended!") 54 break 55 if mode == 0: 56 if keyboard.read_key() == toggle_button: 57 key = 1 58 print("Anti-recoil ENABLED") 59 if is_mouse_down() and key == 1 : 60 win32api.mouse_event(0x0001, horizontal, vertical) 61 time.sleep(firerate) 62 win32api.mouse_event(0x0001, horizontal, vertical2) 63 time.sleep(firerate) 64 win32api.mouse_event(0x0001, horizontal2, vertical2) 65 time.sleep(firerate) 66 win32api.mouse_event(0x0001, horizontal2, vertical) 67 time.sleep(firerate) 68window.close()
試したこと
window.refresh()をtime.sleepの後に入れた
補足情報(FW/ツールのバージョンなど)
Python 3.11.1
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。