메뉴 여닫기
개인 메뉴 토글
로그인하지 않음
만약 지금 편집한다면 당신의 IP 주소가 공개될 수 있습니다.

커서 위치 추적

데브카페

; 초기 커서 위치 설정
Local $iCursorPos = StringLen(ControlGetText($hActiveWindow, "", $hFocusedControl))

; 커서 이동 후 위치 추적
Func UpdateCursor($iMoveBy)
    $iCursorPos += $iMoveBy
    If $iCursorPos < 1 Then $iCursorPos = 1
    If $iCursorPos > StringLen(ControlGetText($hActiveWindow, "", $hFocusedControl)) Then $iCursorPos = StringLen(ControlGetText($hActiveWindow, "", $hFocusedControl))
    Return $iCursorPos
EndFunc

커서 위치의 문자 인식

#include <MsgBoxConstants.au3>

; 활성 창 및 컨트롤 정보 가져오기
Local $hActiveWindow = WinGetHandle("[ACTIVE]")
Local $hFocusedControl = ControlGetFocus($hActiveWindow)

; 텍스트 읽기
If $hFocusedControl <> "" Then
    ; 현재 컨트롤의 전체 텍스트 가져오기
    Local $sText = ControlGetText($hActiveWindow, "", $hFocusedControl)
    
    ; 커서 이동 (5칸 왼쪽으로 이동)
    ControlSend($hActiveWindow, "", $hFocusedControl, "{LEFT 5}")
    
    ; 내부적으로 커서가 이동한 후 문자를 읽기
    Local $iCursorPos = StringLen($sText) - 5 ; 현재 커서 위치를 계산
    If $iCursorPos > 0 Then
        ; 해당 위치의 문자 추출
        Local $sChar = StringMid($sText, $iCursorPos, 1)
        MsgBox($MB_ICONINFORMATION, "Character at Cursor", "Character at cursor: " & $sChar)
    Else
        MsgBox($MB_ICONWARNING, "Error", "Cursor is out of bounds!")
    EndIf
Else
    MsgBox($MB_ICONERROR, "Error", "No focused control found!")
EndIf

Comments