Changing the system cursor (using SetSystemCursor)
https://www.autohotkey.com/board/topic/32608-changing-the-system-cursor/
problems 1:
The changed Cursor is blurred.
problems 2:
when the Cursor is in a certain position of a program, the program will automatically change the shape of the Cursor.
Check out the 3 screenshots below:
Number 1, the normal shape of the Cursor.
Number 2, the Cursor modified with SetSystemCursor method, is blurred.
Number 3, move the Cursor in the second picture to the left, and the shape of the mouse is changed by the program (NotePad++).
I have seen some third screenshot tools. When taking screenshots, they will change the shape of the cursor without the above two problems.
It doesn't seem difficult to achieve.
How can you solve these two problems?
Here is my test script, I modified SetSystemCursor to SetSystemCursor2, which can solve the fuzzy problem,
but when in different positions, the cursor seems to be a bit messy。
press F1 to change/resotre Cursor Shape:
Code: Select all
#SingleInstance Force
F1::
if(flag := !flag)
{
SetSystemCursor( "IDC_HAND") ;IDC_ARROW IDC_CROSS
;SetSystemCursor2( "IDC_HAND")
}
else
RestoreCursors()
return
SetSystemCursor(Cursor) {
Static
Initialized := False
SystemCursors := "32512IDC_ARROW|32513IDC_IBEAM|32514IDC_WAIT|32515IDC_CROSS|"
. "32516IDC_UPARROW|32642IDC_SIZENWSE|"
. "32643IDC_SIZENESW|32644IDC_SIZEWE|32645IDC_SIZENS|32646IDC_SIZEALL|"
. "32648IDC_NO|32649IDC_HAND|32650IDC_APPSTARTING|32651IDC_HELP"
If !(Initialized) { ; load system cursors only once
Loop, Parse, SystemCursors, |
{
CID := SubStr(A_LoopField, 1, 5) ;32512
CNA := SubStr(A_LoopField, 6) ;IDC_ARROW
HC%CNA% := DllCall("LoadCursor", "UInt", 0, "Int", CID)
}
Initialized := True
}
If !(HC%Cursor%) {
Msgbox, 0, SetSystemCursor, Error: Invalid cursor name %Cursor%
Return False
}
Loop, Parse, SystemCursors, |
{
CID := SubStr(A_LoopField, 1, 5)
;This way, the Cursor becomes blurry
HCUR := DllCall("CopyIcon", "UInt" , HC%Cursor%)
DllCall("SetSystemCursor", "UInt", HCUR, "Int", CID)
;It is clear to use the original CursorHandle setting directly.
;But the Cursor seems to be messed up
;DllCall("SetSystemCursor", "UInt", HC%Cursor%, "Int", CID)
}
Return True
}
SetSystemCursor2(Cursor) {
Static
Initialized := False
SystemCursors := "32512IDC_ARROW|32513IDC_IBEAM|32514IDC_WAIT|32515IDC_CROSS|"
. "32516IDC_UPARROW|32642IDC_SIZENWSE|"
. "32643IDC_SIZENESW|32644IDC_SIZEWE|32645IDC_SIZENS|32646IDC_SIZEALL|"
. "32648IDC_NO|32649IDC_HAND|32650IDC_APPSTARTING|32651IDC_HELP"
If !(Initialized) { ; load system cursors only once
Loop, Parse, SystemCursors, |
{
CID := SubStr(A_LoopField, 1, 5) ;32512
CNA := SubStr(A_LoopField, 6) ;IDC_ARROW
HC%CNA% := DllCall("LoadCursor", "UInt", 0, "Int", CID)
}
Initialized := True
}
If !(HC%Cursor%) {
Msgbox, 0, SetSystemCursor, Error: Invalid cursor name %Cursor%
Return False
}
Loop, Parse, SystemCursors, |
{
CID := SubStr(A_LoopField, 1, 5)
;This way, the Cursor becomes blurry
HCUR := DllCall("CopyIcon", "UInt" , HC%Cursor%)
;DllCall("SetSystemCursor", "UInt", HCUR, "Int", CID)
;It is clear to use the original CursorHandle setting directly.
;But the Cursor seems to be messed up
DllCall("SetSystemCursor", "UInt", HC%Cursor%, "Int", CID)
}
Return True
}
RestoreCursors()
{
SPI_SETCURSORS := 0x57
DllCall( "SystemParametersInfo", UInt,SPI_SETCURSORS, UInt,0, UInt,0, UInt,0 )
}
esc::
RestoreCursors()
ExitApp
return