使用autohotkey gui在任何应用程序上输入文本

时间:2018-05-07 06:40:16

标签: autohotkey

我正在尝试找到一个解决方案,将预定义文本添加到任何应用程序中,而不是记住热键/热字符串组合,我只需要点击文本的GUI按钮。

这就是我现在所拥有的:

Gui, Add, Button, x22 y20 w120 h40 , Title
Gui, Add, Button, x22 y70 w120 h40 , Paragraph
; Generated using SmartGUI Creator 4.0
Gui, Show, x152 y89 h131 w222, New GUI Window
Return

ButtonTitle:
Send Title
return

ButtonParagraph:
Send Paragraph 
return

GuiClose:
ExitApp

我的问题是我无法使其正常工作。我只想点击按钮,该单词将被拍摄到记事本/单词/任何应用程序。

2 个答案:

答案 0 :(得分:0)

解决方案是始终跟踪当前和最后一个活动窗口。为了实现这一点,您可以使用shell挂钩在活动窗口更改时收到通知:https://autohotkey.com/board/topic/66726-method-to-detect-active-window-change/

因此,您可以有两个变量currentWinlastWin,当活动窗口发生变化时,您需要设置lastWin := currentWincurrentWin := activeWin

这样的事情可能是:

Gui, Add, Button, x22 y20 w120 h40 , Title
Gui, Add, Button, x22 y70 w120 h40 , Paragraph
; Generated using SmartGUI Creator 4.0
Gui, Show, x152 y89 h131 w222, New GUI Window

Gui +LastFound 
hWnd := WinExist()
DllCall( "RegisterShellHookWindow", UInt,Hwnd )
MsgNum := DllCall( "RegisterWindowMessage", Str,"SHELLHOOK" )
OnMessage( MsgNum, "ShellMessage" )
Return

ShellMessage(wParam, lParam) {
    If (wParam=4) { ;HSHELL_WINDOWACTIVATED
        lastWin := currentWin
        currentWin := "ahk_id " . lParam
    }
}

ButtonTitle:
WinActivate, % lastWin
Send Title
return

ButtonParagraph:
WinActivate, % lastWin
Send Paragraph 
return

GuiClose:
ExitApp

(完全未经测试)

答案 1 :(得分:0)

嗨Stephan和Forivin,

感谢您的帮助。我使用alt + tab方法来解决问题,虽然我需要确保我在alt + tab键击上得到记事本,否则它会转到另一个应用程序。以下解决了这个问题。

Gui,Add,Button,x22 y20 w120 h40,Title
Gui,Add,Button,x22 y70 w120 h40,第
一段 Gui,Show,x152 y89 h131 w222,新的GUI窗口
返回

按钮名称:
发送,!{Esc}
发送标题
返回

ButtonParagraph:
发送,!{Esc}
发送段落
返回

GuiClose:
ExitApp命令