autohotkey 记录

https://www.autohotkey.com/
记录

https://www.autohotkey.com/docs/v2/

https://www.autohotkey.com/docs/v2/lib/Send.htm

https://www.autohotkey.com/boards/

https://www.autoahk.com/
中文社区

#z::Run "https://www.autohotkey.com"  ; Win+Z
#n::Run "mspaint"  ; Win+n

^!n::  ; Ctrl+Alt+N
{
    if WinExist("Untitled - Notepad")
        WinActivate
    else
        Run "Notepad"
}

22

Run "notepad.exe"
if WinWait("无标题 - 记事本", , 3){    
    WinMinimize ; Use the window found by WinWait.
    MsgBox "WinWait not timed out."
    
}
else{
    MsgBox "WinWait timed out."
}

xshell 子窗口关闭

v2

Run "xshell.exe"
if WinWait("Xshell 5 (Free for Home/School)", , 6){    
   ; WinMinimize ; Use the window found by WinWait.
    MsgBox "WinWait not timed out."
    SetTimer CheckForMsgBox, 100 
    CheckForMsgBox()
    {
        If WinExist("会话") 
        {
         Send "{Enter}" 
         SetTimer CheckForMsgBox,0             
        }
    

    }
}
else{
    MsgBox "WinWait timed out."
}

在这里插入图片描述

通达信自动下载 盘后数据 AHK V2

Run "C:\\new_tdx\\TdxW.exe"
if WinWait("通达信金融终端V7.48", , 6){    
   ; WinMinimize ; Use the window found by WinWait.
    ;MsgBox "WinWait not timed out."
    ControlChooseIndex(2,"SysTabControl321")
    Sleep 1500
    ;ControlClick "Button1"
	Click 530, 262
    Sleep 2500
    
    If WinExist("通达信信息") 
    {
     WinClose ;
          
    }    
    
    If WinExist("数据维护工具V3.90 [通达信金融终端]") 
    {
     WinClose ;
          
    }  	
	Sleep 500
	;PostMessage 0x111, 33233, 0,, "ahk_class TdxW_MainFrame_Class"
	PostMessage 0x111, 9279, 0,, "ahk_class TdxW_MainFrame_Class"
	
	Sleep 2500
	
    If WinExist("盘后数据下载") 
    {
		;ControlClick "Button1", "盘后数据下载"			
		Click 23, 75
		Sleep 500
		ControlClick "Button9", "盘后数据下载"
		;Sleep 9500
		;WinClose ;
    } 	


}
else{
    MsgBox "WinWait timed out."
}

在这里插入图片描述

在这里插入图片描述

辅助工具:

;AHK v1.1 x64/x32 compatible update by jeeswg of:
;Get Info from Context Menu - Scripts and Functions - AutoHotkey Community
;https://autohotkey.com/board/topic/19754-get-info-from-context-menu/
 
;
; AutoHotkey Version: 1.x
; Language:       English
; Platform:       Win9x/NT
; Author:         micha
;
; Script Function:
;	Demonstrates how to retrieve infos from a context/ popup menu
;
 
/*
This is the struct we are using.
typedef struct tagMENUITEMINFO {
	UINT    cbSize;
	UINT    fMask;
	UINT    fType;
	UINT    fState;
	UINT    wID;
	HMENU   hSubMenu;
	HBITMAP hbmpChecked;
	HBITMAP hbmpUnchecked;
	ULONG_PTR dwItemData;
	LPTSTR  dwTypeData;
	UINT    cch;
	HBITMAP hbmpItem;
} MENUITEMINFO, *LPMENUITEMINFO;
 
*/
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
#Persistent
RunAsAdmin() 
SetTimer, Demo, 500
return
Demo:
;constants
MFS_ENABLED = 0
MFS_CHECKED = 8
MFS_DEFAULT = 0x1000
MFS_DISABLED = 2
MFS_GRAYED = 1
MFS_HILITE = 0x80
;MFS_UNCHECKED = 0
;MFS_UNHILITE = 0
;Get mouse position and handle to wnd under the mouse cursor
MouseGetPos, MouseScreenX, MouseScreenY, MouseWindowUID, MouseControlID
WinGet,ControlHwnd, ID,ahk_id %MouseWindowUID%
;Get count of menu items
ContextMenCnt := GetContextMenuCount(ControlHwnd)
if ContextMenCnt < 1
{
	Tooltip,
	return
}
TooltipText =
;Read info for each menu item
loop, %ContextMenCnt%
{
	IsEnabled := GetContextMenuState(ControlHwnd, a_index-1)
	{
		CurrentText =
		;~ if IsEnabled = 0
		;~ CurrentText = %CurrentText% Enabled
		;~ if (IsEnabled & MFS_CHECKED)
		;~ CurrentText = %CurrentText% Checked
		;~ if (IsEnabled & MFS_DEFAULT)
		;~ CurrentText = %CurrentText% Default
		;~ if (IsEnabled & MFS_DISABLED)
		;~ CurrentText = %CurrentText% Disabled
		;~ if (IsEnabled & MFS_GRAYED)
		;~ CurrentText = %CurrentText% Grayed
		;~ if (IsEnabled & MFS_HILITE)
		;~ CurrentText = %CurrentText% Highlight
		;~ TooltipText = %TooltipText%%a_index%:%CurrentText%`n
		if (IsEnabled & MFS_HILITE)
        {
		CurrentText := GetContextMenuID(ControlHwnd, a_index-1) . A_Tab . GetContextMenuText(ControlHwnd, a_index-1)
        TooltipText := CurrentText    
		}
	}
}
;~ TextText =
;~ loop, %ContextMenCnt%
;~ {
	;~ StrSize := GetContextMenuText(ControlHwnd, a_index-1)
	;~ nID := GetContextMenuID(ControlHwnd, a_index-1)
	;~ TextText = %TextText%%a_index%:%StrSize%-ID=%nID%`n
;~ }
CoordMode, Tooltip, Screen
Tooltip, %TooltipText%---`n%TextText%, 0, 0
return
/***************************************************************
* returns the count of menu items
***************************************************************
*/
GetContextMenuCount(hWnd)
{
	WinGetClass, WindowClass, ahk_id %hWnd%
	;All popups should have the window class #32768
	if WindowClass <> #32768
	{
		return 0
	}
	; Retrieve menu handle from window
	SendMessage, 0x01E1, , , , ahk_id %hWnd%
	;Errorlevel is set by SendMessage. It contains the handle to the menu
	hMenu := errorlevel
	menuitemcount:=DllCall("GetMenuItemCount", Ptr,hMenu)
	Return, menuitemcount
}
/***************************************************************
* returns the state of a menu entry
***************************************************************
*/
GetContextMenuState(hWnd, Position)
{
	WinGetClass, WindowClass, ahk_id %hWnd%
	if WindowClass <> #32768
	{
		return -1
	}
	SendMessage, 0x01E1, , , , ahk_id %hWnd%
	;Errorlevel is set by SendMessage. It contains the handle to the menu
	hMenu := errorlevel
	;We need to allocate a struct
	VarSetCapacity(MenuItemInfo, 60, 0)
	;Set Size of Struct to the first member
	NumPut(A_PtrSize=8?80:48, MenuItemInfo, 0, "UInt")
	;Get only Flags from dllcall GetMenuItemInfo MIIM_TYPE = 1
	NumPut(1, MenuItemInfo, 4, "UInt")
	;GetMenuItemInfo: Handle to Menu, Index of Position, 0=Menu identifier / 1=Index
	InfoRes := DllCall("user32.dll\GetMenuItemInfo", Ptr,hMenu, UInt,Position, Int,1, Ptr,&MenuItemInfo)
	InfoResError := errorlevel
	LastErrorRes := DllCall("GetLastError", UInt)
	if InfoResError <> 0
	return -1
	if LastErrorRes != 0
	return -1
	;Get Flag from struct
	GetMenuItemInfoRes := NumGet(MenuItemInfo, 12, "UInt")
	/*
	IsEnabled = 1
	if GetMenuItemInfoRes > 0
	IsEnabled = 0
	return IsEnabled
	*/
	return GetMenuItemInfoRes
}
/***************************************************************
* returns the ID of a menu entry
***************************************************************
*/
GetContextMenuID(hWnd, Position)
{
	WinGetClass, WindowClass, ahk_id %hWnd%
	if WindowClass <> #32768
	{
		return -1
	}
	SendMessage, 0x01E1, , , , ahk_id %hWnd%
	;Errorlevel is set by SendMessage. It contains the handle to the menu
	hMenu := errorlevel
	;UINT GetMenuItemID(          HMENU hMenu,    int nPos);
	InfoRes := DllCall("user32.dll\GetMenuItemID", Ptr,hMenu, Int,Position, UInt)
	InfoResError := errorlevel
	LastErrorRes := DllCall("GetLastError", UInt)
	if InfoResError <> 0
	return -1
	if LastErrorRes != 0
	return -1
	return InfoRes
}
/***************************************************************
* returns the text of a menu entry (standard windows context menus only!!!)
***************************************************************
*/
GetContextMenuText(hWnd, Position)
{
	WinGetClass, WindowClass, ahk_id %hWnd%
	if WindowClass <> #32768
	{
		return -1
	}
	SendMessage, 0x01E1, , , , ahk_id %hWnd%
	;Errorlevel is set by SendMessage. It contains the handle to the menu
	hMenu := errorlevel
	;We need to allocate a struct
	VarSetCapacity(MenuItemInfo, 200, 0)
	;Set Size of Struct (48) to the first member
	NumPut(A_PtrSize=8?80:48, MenuItemInfo, 0, "UInt")
	;Retrieve string MIIM_STRING = 0x40 = 64 (/ MIIM_TYPE = 0x10 = 16)
	NumPut(64, MenuItemInfo, 4, "UInt")
	;Set type - Get only size of string we need to allocate
	;NumPut(0, MenuItemInfo, 8, "UInt")
	;GetMenuItemInfo: Handle to Menu, Index of Position, 0=Menu identifier / 1=Index
	InfoRes := DllCall("user32.dll\GetMenuItemInfo", Ptr,hMenu, UInt,Position, Int,1, Ptr,&MenuItemInfo)
	if InfoRes = 0
	return -1
	InfoResError := errorlevel
	LastErrorRes := DllCall("GetLastError", UInt)
	if InfoResError <> 0
	return -1
	if LastErrorRes <> 0
	return -1
	;Get size of string from struct
	GetMenuItemInfoRes := NumGet(MenuItemInfo, A_PtrSize=8?64:40, "UInt")
	;If menu is empty return
	If GetMenuItemInfoRes = 0
	return "{Empty String}"
	;+1 should be enough, we'll use 2
	GetMenuItemInfoRes += 2
	;Set capacity of string that will be filled by windows
	VarSetCapacity(PopupText, GetMenuItemInfoRes, 0)
	;Set Size plus 0 terminator + security ;-)
	NumPut(GetMenuItemInfoRes, MenuItemInfo, A_PtrSize=8?64:40, "UInt")
	NumPut(&PopupText, MenuItemInfo, A_PtrSize=8?56:36, "Ptr")
	InfoRes := DllCall("user32.dll\GetMenuItemInfo", Ptr,hMenu, UInt,Position, Int,1, Ptr,&MenuItemInfo)
	if InfoRes = 0
	return -1
	InfoResError := errorlevel
	LastErrorRes := DllCall("GetLastError", UInt)
	if InfoResError <> 0
	return -1
	if LastErrorRes <> 0
	return -1
	return PopupText
}
;PrintScreen::reload
RunAsAdmin() {
	full_command_line := DllCall("GetCommandLine", "str")
	if not (A_IsAdmin or RegExMatch(full_command_line, " /restart(?!\S)"))
	{
		try
		{
			if A_IsCompiled
				Run *RunAs "%A_ScriptFullPath%" /restart
			else
				Run *RunAs "%A_AhkPath%" /restart "%A_ScriptFullPath%"
		}
		ExitApp
	}
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 您可以使用 AutoHotkey 的 `MouseGetPos` 函数来记录当前光标的位置。 例如,下面是一个简单的脚本,可以在按下 `F1` 键时记录当前光标的坐标并在消息框中显示它: ``` F1:: MouseGetPos, x, y MsgBox, The current cursor position is X:%x% Y:%y% return ``` 您也可以使用 `GetCursorPos` 函数来获取光标的位置。 例如: ``` DllCall("GetCursorPos", "uint", x, "uint", y) ``` 希望这可以帮助您。 ### 回答2: AutoHotkey是一种脚本语言,可以用来自动化任务和快捷键绑定等。以下是使用AutoHotkey记录当前光标位置的方法: 首先,我们可以使用AutoHotkey提供的`CoordMode`命令来设置坐标模式。默认情况下,AutoHotkey使用相对于活动窗口的坐标模式。我们可以将坐标模式设置为屏幕坐标模式,这样可以确保光标位置的准确性。具体代码如下: ``` CoordMode, Mouse, Screen ``` 接下来,我们可以使用`MouseGetPos`命令来获取当前光标的位置,并将其保存到变量中。代码如下所示: ``` MouseGetPos, mouseX, mouseY ``` 上述代码将当前光标的X坐标保存到`mouseX`变量中,将Y坐标保存到`mouseY`变量中。 最后,我们可以使用`MsgBox`命令来弹出消息框,显示当前光标位置的坐标。代码如下: ``` MsgBox, 当前光标位置为:X:%mouseX%,Y:%mouseY% ``` 上述代码中的`%mouseX%`和`%mouseY%`是变量的引用,会被其对应的值替代。 通过上述代码,我们就可以记录当前光标的位置,并将其显示在一个消息框中。这样,我们就可以通过一个自定义的快捷键来获取当前光标的位置了。 当然,AutoHotkey还提供了其他丰富的功能,我们可以根据具体需求进行灵活的编写和扩展。 ### 回答3: AutoHotkey 是一种功能强大的自动化脚本语言,可以用于自动化键盘和鼠标操作。要记录当前光标位置,我们可以使用 AutoHotkey 的相关函数和命令。下面是一个简单的示例脚本来记录当前光标位置: ``` #NoEnv SetBatchLines, -1 ; 创建一个存储光标位置的全局变量 global cursorX, cursorY ; 定义一个快捷键来记录光标位置 ^!s:: GetCursorPos, cursor cursorX := cursor.x cursorY := cursor.y ToolTip, 当前光标位置已记录:%cursorX%, %cursorY% Sleep, 2000 ToolTip return ``` 在上面的脚本中,我们使用了 `GetCursorPos` 函数来获取光标的当前位置,并将其存储在 `cursorX` 和 `cursorY` 全局变量中。我们通过按下“Ctrl + Alt + S”快捷键来触发记录光标位置的操作。当记录完成后,脚本会显示一个提示框,显示已记录的光标位置,并保持2秒后自动关闭。 通过运行上述脚本,我们可以方便地记录光标的当前位置。每当我们需要使用这些记录的光标位置时,只需访问全局变量 `cursorX` 和 `cursorY` 即可。这样我们就可以根据需要在 AutoHotkey 脚本中使用光标位置来执行其他操作。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值