first commit
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
import uiautomation as auto
|
||||
import time
|
||||
|
||||
def is_editable_focused():
|
||||
try:
|
||||
focused = auto.GetFocusedControl()
|
||||
if not focused:
|
||||
return False
|
||||
|
||||
# Проверяем тип элемента
|
||||
control_type = focused.ControlType
|
||||
# EditControl — это текстовое поле ввода в Windows UI Automation
|
||||
if control_type == auto.ControlType.EditControl:
|
||||
return True
|
||||
|
||||
# Также можно проверить по классу (например, для браузеров)
|
||||
class_name = focused.ClassName
|
||||
# Например, Chrome использует класс 'Chrome_RenderWidgetHostHWND'
|
||||
# Но это менее надёжно; лучше использовать UIA
|
||||
|
||||
return False
|
||||
except Exception as e:
|
||||
print(f"Ошибка: {e}")
|
||||
return False
|
||||
|
||||
def main():
|
||||
print("Отслеживание фокуса в текстовых полях...")
|
||||
last_state = False
|
||||
while True:
|
||||
current_state = is_editable_focused()
|
||||
if current_state and not last_state:
|
||||
print("Текстовое поле получило фокус!")
|
||||
last_state = current_state
|
||||
time.sleep(0.5) # Проверка 2 раза в секунду
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user