使用 AutoIt 跨环境更改鼠标光标
Change mouse cursor across environment with AutoIt
我希望这是可行的...我使用驻留在系统托盘中的 AutoIt 创建了一个程序。托盘项目之一运行等待用户单击 window 以获取 window 标题的功能(它可以是任何 window,不一定是由 AutoIt 制作的。这部分工作完美。
我想要在等待用户单击时将鼠标光标更改为十字的功能。我试过使用 GUISetCursor(3),但据我了解,这只会更改 AutoIt GUI window.
的光标
我怎样才能为用户环境更改鼠标光标,而不仅仅是为 AutoIt window?
你可以这样做:
#include <Misc.au3>
#include <WindowsConstants.au3>
GetTitleByClick()
Func GetTitleByClick()
Local $hCursor = GUICreate('', 48, 48, -1, -1, $WS_POPUP, $WS_EX_TOPMOST)
WinSetTrans($hCursor, '', 10)
GUISetCursor(3, 1, $hCursor)
GUISetState(@SW_SHOW, $hCursor)
; get title bar position
Local $pos
Do
$pos = MouseGetPos()
WinMove($hCursor, '', $pos[0]-24, $pos[1]-24)
Sleep(10)
Until _IsPressed('01')
GUIDelete($hCursor)
; block mouse
_MouseTrap($pos[0], $pos[1], $pos[0]+1, $pos[0]+1)
; click position - activates the window
MouseClick('left', $pos[0], $pos[1])
; unblock mouse
_MouseTrap()
; get the title of the active window
Local $sTitle = WinGetTitle('[ACTIVE]')
Return MsgBox(0, 'TITLE', $sTitle)
EndFunc
感谢 Richard 的评论,以及 AutoIt 论坛中将我链接到 AutoIt 的 _WinAPI_SetSystemCursor 功能的回复,我能够使它正常工作。
我从 %SystemRoot%\Cursors 复制了我想要的十字光标(具体来说,我复制了 cross_i.cur)到我脚本的源目录中。
然后,在执行程序的暴力函数中,我添加了以下行:
Func FuncName()
;backs up the user's arrow cursor
Local $hPrev = _WinAPI_CopyCursor(_WinAPI_LoadCursor(0, 32512))
;backs up the user's ibeam cursor
Local $iPrev = _WinAPI_CopyCursor(_WinAPI_LoadCursor(0, 32513))
;changes the user's arrow cursor
_WinAPI_SetSystemCursor(_WinAPI_LoadCursorFromFile(@ScriptDir & "\cross.cur"),32512)
;changes the user's ibeam cursor
_WinAPI_SetSystemCursor(_WinAPI_LoadCursorFromFile(@ScriptDir & "\cross.cur"),32513)
; Do the code you want to execute
;restores the user's default cursor
_WinAPI_SetSystemCursor($hPrev,32512)
;restores the user's ibeam cursor
_WinAPI_SetSystemCursor($iPrev,32513)
EndFunc
这让我完成了我需要的事情。
我希望这是可行的...我使用驻留在系统托盘中的 AutoIt 创建了一个程序。托盘项目之一运行等待用户单击 window 以获取 window 标题的功能(它可以是任何 window,不一定是由 AutoIt 制作的。这部分工作完美。
我想要在等待用户单击时将鼠标光标更改为十字的功能。我试过使用 GUISetCursor(3),但据我了解,这只会更改 AutoIt GUI window.
的光标我怎样才能为用户环境更改鼠标光标,而不仅仅是为 AutoIt window?
你可以这样做:
#include <Misc.au3>
#include <WindowsConstants.au3>
GetTitleByClick()
Func GetTitleByClick()
Local $hCursor = GUICreate('', 48, 48, -1, -1, $WS_POPUP, $WS_EX_TOPMOST)
WinSetTrans($hCursor, '', 10)
GUISetCursor(3, 1, $hCursor)
GUISetState(@SW_SHOW, $hCursor)
; get title bar position
Local $pos
Do
$pos = MouseGetPos()
WinMove($hCursor, '', $pos[0]-24, $pos[1]-24)
Sleep(10)
Until _IsPressed('01')
GUIDelete($hCursor)
; block mouse
_MouseTrap($pos[0], $pos[1], $pos[0]+1, $pos[0]+1)
; click position - activates the window
MouseClick('left', $pos[0], $pos[1])
; unblock mouse
_MouseTrap()
; get the title of the active window
Local $sTitle = WinGetTitle('[ACTIVE]')
Return MsgBox(0, 'TITLE', $sTitle)
EndFunc
感谢 Richard 的评论,以及 AutoIt 论坛中将我链接到 AutoIt 的 _WinAPI_SetSystemCursor 功能的回复,我能够使它正常工作。
我从 %SystemRoot%\Cursors 复制了我想要的十字光标(具体来说,我复制了 cross_i.cur)到我脚本的源目录中。
然后,在执行程序的暴力函数中,我添加了以下行:
Func FuncName()
;backs up the user's arrow cursor
Local $hPrev = _WinAPI_CopyCursor(_WinAPI_LoadCursor(0, 32512))
;backs up the user's ibeam cursor
Local $iPrev = _WinAPI_CopyCursor(_WinAPI_LoadCursor(0, 32513))
;changes the user's arrow cursor
_WinAPI_SetSystemCursor(_WinAPI_LoadCursorFromFile(@ScriptDir & "\cross.cur"),32512)
;changes the user's ibeam cursor
_WinAPI_SetSystemCursor(_WinAPI_LoadCursorFromFile(@ScriptDir & "\cross.cur"),32513)
; Do the code you want to execute
;restores the user's default cursor
_WinAPI_SetSystemCursor($hPrev,32512)
;restores the user's ibeam cursor
_WinAPI_SetSystemCursor($iPrev,32513)
EndFunc
这让我完成了我需要的事情。