11import ctypes
22from ctypes .wintypes import *
3- from Engine .Logging import *
4- from Engine .Byte import *
53
64# CTYPES ADAPTATE -------------------------------
75
@@ -157,7 +155,7 @@ def init(useHotkey=False, lineInput=False, echo=False, resizeEvents=False, mouse
157155 """Включает получение событий\n Принимает: (bool) useHotkey - использование горячих клавиш, (bool) lineInput - описание отсутствует, (bool) echo - добавление в выходной массив, (bool) resizeEvents - принятие событий изменения размеров окна, (bool) mouseEvents - принятие событий мыши, (bool) insert - включает insert, (bool) quickEdit - выделение мышью, (bool) extended - запрет quickEdit"""
158156 Input .handle = ctypes .windll .kernel32 .GetStdHandle (- 10 )
159157 Input .events = ctypes .wintypes .DWORD ()
160- Input .InputRecord = INPUT_RECORD ()
158+ Input .record = INPUT_RECORD ()
161159
162160 out = 0
163161
@@ -176,51 +174,54 @@ def init(useHotkey=False, lineInput=False, echo=False, resizeEvents=False, mouse
176174
177175 def reset ():
178176 """Отчистка входного буффера"""
179- prev = 0
177+
178+ # Получаем события
180179 Input .tick ()
181- while int (bytes (Input .events )[0 ]) != 0 :
180+
181+ # Если кол-во принятых событий не равно 0 то принимаем еще
182+ while Input .eventsRecived != False :
182183 Input .tick ()
183184
185+ # Присваиваем переменным стандартные значения
184186 Input .varInit ()
185187
186188 def varInit ():
187189 """Сброс / инициализация переменных"""
190+ Input .event = 0
188191 Input .eventType = 0
189192
190193 Input .mouseX = 0
191194 Input .mouseY = 0
192195 Input .mouseKey = 0
193-
196+ Input . prevMouseState = False
194197 Input .mouseType = 0
195198
196199 Input .keyboardCode = 0
197200 Input .keyboardChar = 0
198201 Input .keyboardState = 0
199202 Input .prevKeyboardState = False
200- Input .prevMouseState = False
201-
202- Input .event = 0
203- Input .eventString = ""
204203
205204 def tick ():
206- """Получение событий, обработка и их запись в массив \n Принимает: (bool) asyn - не ждать события """
205+ """Получение и запись событий """
207206
208- ctypes . windll . kernel32 . ReadConsoleInputExW ( Input . handle , ctypes . byref ( Input . InputRecord ), 1 , ctypes . byref ( Input . events ), 2 )
209- record = Input .InputRecord
207+ # Принимаем события от консоли
208+ ctypes . windll . kernel32 . ReadConsoleInputExW ( Input . handle , ctypes . byref ( Input . record ), 1 , ctypes . byref ( Input .events ), 2 )
210209
211- Input . event = record . Event
212- Input .eventType = record . EventType
210+ # Определяет есть ли новые события
211+ Input .eventsRecived = bool ( int ( bytes ( Input . events )[ 0 ]))
213212
214- Input .mouseX = Input .event .MouseEvent .dwMousePosition .X # X
215- Input .mouseY = Input .event .MouseEvent .dwMousePosition .Y # Y
216- Input .mouseKey = Input .event .MouseEvent .dwButtonState # какая кнопка клавиатуры нажата
213+ # Записываем все в удобные для работы переменные
214+ Input .event = Input .record .Event
215+ Input .eventType = Input .record .EventType
216+
217+ Input .mouseX = Input .event .MouseEvent .dwMousePosition .X
218+ Input .mouseY = Input .event .MouseEvent .dwMousePosition .Y
219+ Input .mouseKey = Input .event .MouseEvent .dwButtonState
217220
218221 Input .prevMouseState = Input .mouseType == Input .Mouse .DOWN
219222 Input .mouseType = Input .event .MouseEvent .dwEventFlags # колесо / нажатие / движение / двойное нажатие
220223
221224 Input .prevKeyboardState = Input .keyboardState if Input .eventType == Input .Types .Keyboard else False
222225 Input .keyboardCode = Input .event .KeyEvent .wVirtualKeyCode # Код кнопки клавиатуры
223226 Input .keyboardChar = Input .event .KeyEvent .uChar .UnicodeChar # Символ клавиши
224- Input .keyboardState = Input .event .KeyEvent .bKeyDown if Input .eventType == Input .Types .Keyboard else False # Состояние кнопки
225-
226- Input .eventString = f"{ Input .mouseX } { Input .mouseY } { Input .mouseKey } { Input .keyboardCode } { Input .keyboardChar } { Input .keyboardState } "
227+ Input .keyboardState = Input .event .KeyEvent .bKeyDown if Input .eventType == Input .Types .Keyboard else False # Состояние кнопки
0 commit comments