如果我将鼠标悬停在坐标区域,如何更改图标鼠标指针
How to Change the icon Mouse Pointer if i Hover a coordinate area
如何更改鼠标指针的图标。
我想要这个: 如果我将我的鼠标设备悬停在一个特殊的 x,y 坐标区域,它会自动更改鼠标指针的图标(如果我到达那个区域),如果我去那个区域之外,它必须将其更改回默认图标。
我确实尝试过使用自动热键语言编写代码。
但这不起作用。
1 - 我需要按键盘上的 F7 键。
2 - 我必须重新启动计算机才能更改鼠标指针的图标。
f7::
RegWrite, REG_SZ, HKEY_CURRENT_USER, Control Panel\Cursors\,Arrow,%SystemRoot%\cursors\aero_link.cur
return
(如果您有一个代码示例是用 Python 或 Msdos 等其他脚本语言编写的,那对我来说没问题。)
AutoHotkey - 下面的代码显示您可以在固定位置更改光标,在本例中为屏幕中间。这是如何实现的,方法是使用内置变量 A_screenHeight 和 A_screenWidth 来定义 Upper/Lower 和 Right/Left 边界。然后使用 Timer 并使用 GetMousePos 命令检查我们的光标是否在这些范围内。如果鼠标在边界内,则调用 Serenity 在 AutoHotkey 论坛上编写的函数 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 )
}
如何更改鼠标指针的图标。
我想要这个: 如果我将我的鼠标设备悬停在一个特殊的 x,y 坐标区域,它会自动更改鼠标指针的图标(如果我到达那个区域),如果我去那个区域之外,它必须将其更改回默认图标。
我确实尝试过使用自动热键语言编写代码。
但这不起作用。
1 - 我需要按键盘上的 F7 键。
2 - 我必须重新启动计算机才能更改鼠标指针的图标。
f7::
RegWrite, REG_SZ, HKEY_CURRENT_USER, Control Panel\Cursors\,Arrow,%SystemRoot%\cursors\aero_link.cur
return
(如果您有一个代码示例是用 Python 或 Msdos 等其他脚本语言编写的,那对我来说没问题。)
AutoHotkey - 下面的代码显示您可以在固定位置更改光标,在本例中为屏幕中间。这是如何实现的,方法是使用内置变量 A_screenHeight 和 A_screenWidth 来定义 Upper/Lower 和 Right/Left 边界。然后使用 Timer 并使用 GetMousePos 命令检查我们的光标是否在这些范围内。如果鼠标在边界内,则调用 Serenity 在 AutoHotkey 论坛上编写的函数 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 )
}