다른 명령
AutoIt를 사용하여 현재 커서 위치의 문자열을 가져오려면 `ControlGetText` 함수를 사용할 수 있습니다. 이 함수는 지정된 컨트롤의 텍스트를 반환합니다. 메모장의 경우, 컨트롤 ID가 일반적으로 "Edit1"이며, 메모장 창의 핸들을 알아야 합니다. 아래는 간단한 예시 코드입니다.
```autoit #include <MsgBoxConstants.au3> Opt("WinTitleMatchMode", 2) ; 윈도우 제목 부분 일치 모드로 설정 $notepadHandle = WinGetHandle("[CLASS:Notepad]") ; 메모장 창의 핸들을 가져옴 $editControlText = ControlGetText($notepadHandle, "", "Edit1") ; "Edit1" 컨트롤의 텍스트를 가져옴 MsgBox($MB_OK, "현재 커서 위치의 문자열", $editControlText) ```
이 코드는 메모장 창의 핸들을 찾아서 "Edit1" 컨트롤에서 텍스트를 가져옵니다. 그러나 메모장이 현재 활성화되어 있고 편집 상태인 경우에만 작동합니다.
마우스 커서 텍스트 복사
#include <WinAPI.au3> #include <Misc.au3> Func _WindowFromPoint($iX,$iY) Local $stInt64,$aRet,$stPoint=DllStructCreate("long;long") DllStructSetData($stPoint,1,$iX) DllStructSetData($stPoint,2,$iY) $stInt64=DllStructCreate("int64",DllStructGetPtr($stPoint)) $aRet=DllCall("user32.dll","hwnd","WindowFromPoint","int64",DllStructGetData($stInt64,1)) If @error Then Return SetError(2,@error,0) If $aRet[0]=0 Then Return SetError(3,0,0) Return $aRet[0] EndFunc Local $hControl, $hWin, $hOldWin, $aMousePos $hOldWin = "" While Not _IsPressed("1B") $aMousePos = MouseGetPos() $hControl=_WindowFromPoint($aMousePos[0],$aMousePos[1]) ; Since _WindowFromPoint() can return 'sub' windows, or control handles, we should seek the owner window $hWin=_WinAPI_GetAncestor($hControl,2) If $hWin <> $hOldWin Then TrayTip("Window Info","Window under mouse = " & WinGetTitle($hWin), 1) $hOldWin = $hWin EndIf Sleep(10) WEnd
마우스 포인터 위치
다음은 실제 화면과 마우스 포인터 아래의 맨 위에 있는 창 주변의 테두리를 표시하는 전체 화면 GUI의 완전한 예입니다. 이 기능은 창의 제목을 콘솔에 쓰는 데 사용됩니다.
Here's a complete example of a full screen GUI, displaying the actual screen and a border around the window that's topmost under the mouse pointer. This function is used to write the Title of the window to console.
#include <Misc.au3> #include <Array.au3> #include <GDIPlus.au3> #include <ScreenCapture.au3> #include <WindowsConstants.au3> HotKeySet("{Esc}", "_Exit") Func _Exit() Exit 0 EndFunc Global $xPosReminder, $yPosReminder $dll = DllOpen("user32.dll") $allWindows = WinList() ; exclude invisible windows from winlist Dim $windows[1] $windows[0] = 0 For $i = 1 to $allWindows[0][0] ; only fetches visible windows If BitAnd(WinGetState($allWindows[$i][1]), 2) Then;AND $allWindows[$i][0] <> "" Then ReDim $windows[$windows[UBound($windows) - 1] + 2] $windows[UBound($windows) - 1] = $windows[UBound($windows) - 2] + 1 $windows[UBound($windows) - 2] = $allWindows[$i][1] EndIf Next ReDim $windows[$windows[UBound($windows) - 1]] _ArrayReverse($windows) ; capture screen without cursor $pos = MouseGetPos() MouseMove(@DesktopWidth, @DesktopHeight, 0) $hBitmap = _ScreenCapture_Capture ("") MouseMove($pos[0], $pos[1], 0) ; create and show new fullscreen gui $hGUI = GUICreate("", @DesktopWidth, @DesktopHeight, 0, 0, $WS_POPUP) GUISetState(@SW_SHOW) ; Initialize GDI+ library _GDIPlus_StartUp() $hImage = _GDIPlus_BitmapCreateFromHBITMAP ($hBitmap) $hGraphics = _GDIPlus_GraphicsCreateFromHWND ($hGUI) $hPen = _GDIPlus_PenCreate(0xFFFF0000, 3, 2) $iX = _GDIPlus_ImageGetWidth($hImage) $iY = _GDIPlus_ImageGetHeight($hImage) _GDIPlus_GraphicsDrawImage($hGraphics, $hImage, 0, 0) Global $oldWindow = 0 ; Wait for Click While True If _IsPressed("01", $dll) Then ; left mouse button $xPos = MouseGetPos(0) $yPos = MouseGetPos(1) ExitLoop EndIf If __MouseMoved() Then ; Erzeugt eine Kopie einer 24 bit Bitmap $hClone = _GDIPlus_BitmapCloneArea($hImage, 0, 0, $iX, $iY, $GDIP_PXF24RGB) $currentWindow = __GetWindowByMousePosition($windows, MouseGetPos(0), MouseGetPos(1)) If $currentWindow <> $oldWindow Then $windowPosition = WinGetPos($currentWindow) ; reduce position and size to desktop space $windowPosition[0] = _Iif($windowPosition[0] < 0, 0, $windowPosition[0]) $windowPosition[1] = _Iif($windowPosition[1] < 0, 0, $windowPosition[1]) $windowPosition[2] = _Iif($windowPosition[2] > @DesktopWidth, @DesktopWidth, $windowPosition[2]) $windowPosition[3] = _Iif($windowPosition[3] > @DesktopHeight, @DesktopHeight, $windowPosition[3]) _GDIPlus_GraphicsDrawImage($hGraphics, $hClone, 0, 0) _GDIPlus_GraphicsDrawRect($hGraphics, $windowPosition[0], $windowPosition[1], $windowPosition[2], $windowPosition[3], $hPen) $oldWindow = $currentWindow EndIf EndIf Sleep(1) WEnd ; Free Ressources _GDIPlus_PenDispose($hPen) _GDIPlus_BitmapDispose($hImage) _GDIPlus_GraphicsDispose($hGraphics) _WinAPI_DeleteObject($hBitmap) _GDIPlus_ShutDown() DllClose($dll) GUISetState(@SW_HIDE) Func __GetWindowByMousePosition($windows, $xPos, $yPos) Local $currentWindow = 0 For $i = 0 to UBound($windows) - 1 $pos = WinGetPos($windows[$i]) If $xPos >= $pos[0] AND $xPos <= $pos[0] + $pos[2] AND $yPos >= $pos[1] AND $yPos <= $pos[1] + $pos[3] Then $currentWindow = $windows[$i] EndIf Next Return $currentWindow EndFunc Func __MouseMoved() Local $actualPos = MouseGetPos() If $xPosReminder <> $actualPos[0] OR $yPosReminder <> $actualPos[1] Then $xPosReminder = $actualPos[0] $yPosReminder = $actualPos[1] Return True Else Return False EndIf EndFunc ConsoleWrite(WinGetTitle(__GetWindowByMousePosition($windows, $xPos, $yPos)) & @CR) Share