AutoHotkey를을 - 아래 코드는 사용자가 커서를 변경할 수 있음을 보여주고있다 고정 된 위치,이 경우에는 화면의 중앙에 위치합니다. 이것이 성취 된 방법은 내장 변수 A_screenHeight와 A_screenWidth를 사용하여 위/아래와 오른쪽/왼쪽 경계를 정의하는 것입니다. 그런 다음 타이머를 사용하여 GetMousePos 명령을 사용하여 커서가 해당 범위 내에 있는지 확인하십시오. 마우스가 범위 내에 있으면 AutoHotkey Forums의 Serenity가 코딩 한 SetSystemCursor() 함수가 호출되며이 함수는 다양한 DllCall을 사용하여 커서를 변경합니다.
#Persistent
#SingleInstance Force
CoordMode, Mouse, Screen
Left := Round((A_screenWidth/2)/2)
Right := Left * 3
Up := Round((A_screenHeight/2)/2)
Down := Up * 3
SetTimer, WatchCursor, 100
OnExit, CleanUp
return
WatchCursor:
MouseGetPos, x, y
If (x >= Left && y >= Up && x <= Right && y <= Down)
applied ?: SetSystemCursor("IDC_CROSS"), applied := true
else
(!applied) ?: RestoreCursors(), applied := false
return
cleanUp:
RestoreCursors()
ExitApp
Return
esc::GoSub, CleanUp
; https://autohotkey.com/board/topic/32608-changing-the-system-cursor/
SetSystemCursor(Cursor = "", cx = 0, cy = 0)
{
BlankCursor := 0, SystemCursor := 0, FileCursor := 0 ; init
SystemCursors = 32512IDC_ARROW,32513IDC_IBEAM,32514IDC_WAIT,32515IDC_CROSS
,32516IDC_UPARROW,32640IDC_SIZE,32641IDC_ICON,32642IDC_SIZENWSE
,32643IDC_SIZENESW,32644IDC_SIZEWE,32645IDC_SIZENS,32646IDC_SIZEALL
,32648IDC_NO,32649IDC_HAND,32650IDC_APPSTARTING,32651IDC_HELP
If Cursor = ; empty, so create blank cursor
{
VarSetCapacity(AndMask, 32*4, 0xFF), VarSetCapacity(XorMask, 32*4, 0)
BlankCursor = 1 ; flag for later
}
Else If SubStr(Cursor,1,4) = "IDC_" ; load system cursor
{
Loop, Parse, SystemCursors, `,
{
CursorName := SubStr(A_Loopfield, 6, 15) ; get the cursor name, no trailing space with substr
CursorID := SubStr(A_Loopfield, 1, 5) ; get the cursor id
SystemCursor = 1
If (CursorName = Cursor)
{
CursorHandle := DllCall("LoadCursor", Uint,0, Int,CursorID)
Break
}
}
If CursorHandle = ; invalid cursor name given
{
Msgbox,, SetCursor, Error: Invalid cursor name
CursorHandle = Error
}
}
Else If FileExist(Cursor)
{
SplitPath, Cursor,,, Ext ; auto-detect type
If Ext = ico
uType := 0x1
Else If Ext in cur,ani
uType := 0x2
Else ; invalid file ext
{
Msgbox,, SetCursor, Error: Invalid file type
CursorHandle = Error
}
FileCursor = 1
}
Else
{
Msgbox,, SetCursor, Error: Invalid file path or cursor name
CursorHandle = Error ; raise for later
}
If CursorHandle != Error
{
Loop, Parse, SystemCursors, `,
{
If BlankCursor = 1
{
Type = BlankCursor
%Type%%A_Index% := DllCall("CreateCursor"
, Uint,0, Int,0, Int,0, Int,32, Int,32, Uint,&AndMask, Uint,&XorMask)
CursorHandle := DllCall("CopyImage", Uint,%Type%%A_Index%, Uint,0x2, Int,0, Int,0, Int,0)
DllCall("SetSystemCursor", Uint,CursorHandle, Int,SubStr(A_Loopfield, 1, 5))
}
Else If SystemCursor = 1
{
Type = SystemCursor
CursorHandle := DllCall("LoadCursor", Uint,0, Int,CursorID)
%Type%%A_Index% := DllCall("CopyImage"
, Uint,CursorHandle, Uint,0x2, Int,cx, Int,cy, Uint,0)
CursorHandle := DllCall("CopyImage", Uint,%Type%%A_Index%, Uint,0x2, Int,0, Int,0, Int,0)
DllCall("SetSystemCursor", Uint,CursorHandle, Int,SubStr(A_Loopfield, 1, 5))
}
Else If FileCursor = 1
{
Type = FileCursor
%Type%%A_Index% := DllCall("LoadImageA"
, UInt,0, Str,Cursor, UInt,uType, Int,cx, Int,cy, UInt,0x10)
DllCall("SetSystemCursor", Uint,%Type%%A_Index%, Int,SubStr(A_Loopfield, 1, 5))
}
}
}
}
RestoreCursors()
{
SPI_SETCURSORS := 0x57
DllCall("SystemParametersInfo", UInt,SPI_SETCURSORS, UInt,0, UInt,0, UInt,0)
}
@ahkcoder 이것은 정확히 내가 원하는 것을 찾고 테스트 해 보았습니다. 나는 Win Registry에서 그것을 비교했다. (내가 그 지역에 도달 할 경우) 는 IDC_CROSS는 cross_r.cur HKEY_CURRENT_USER \ 제어판 \ 커서 \ 십자선 \는 % SystemRoot % \ 커서로 변경됩니다 아이콘입니다 \ cross_r.cur 와 나는를 변경하려는 경우 상. 다음 내가 코드 라인에 IDC_HAND 에 IDC_CROSS를 대체 할 수있다 : 적용 : SetSystemCursor ("IDC_CROSS")를 적용 : = 사실 IDC_HAND 다음 aero_link.cur HKEY_CURRENT_USER \ 제어판 \ 커서로 변경됩니다 아이콘입니다 \ Hand \ % SystemRoot % \ cursors \ aero_link.cur – stevecody
예, SetSystemCursor()에 전달 된 값을 SetSystemCursor ("IDC_HAND")로 변경하십시오. 시스템 아이콘의 목록 : 답변으로 IDC_ARROW IDC_IBEAM IDC_WAIT IDC_CROSS IDC_UPARROW IDC_SIZE IDC_ICON IDC_SIZENWSE IDC_SIZENESW IDC_SIZEWE IDC_SIZENS IDC_SIZEALL IDC_NO IDC_HAND IDC_APPSTARTING IDC_HELP 이를 받아 주시겠습니까 ? – errorseven
restorecursors에 대한 함수 호출을 줄이기위한 추가 코드와 커서가 복원되도록 보장하는 onexit 서브 루틴을 추가했습니다. – errorseven