Autohotkey 使用自动热键gui在任何应用程序上输入文本

Autohotkey 使用自动热键gui在任何应用程序上输入文本,autohotkey,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

我试图找到一个解决方案,将预定义文本添加到任何应用程序中,因此,我不需要记住热键/热字符串组合,只需单击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

我的问题是我不能使它正常工作。我只想点击这个按钮,word就会被弹出到记事本/word/任何应用程序。

解决方案是始终跟踪当前和最后一个活动窗口。要实现这一点,可以使用shell钩子在活动窗口更改时获得通知:

因此,您可以有两个变量
currentWin
lastWin
,当活动窗口更改时,您可以设置
lastWin:=currentWin
currentWin:=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

(完全未经测试)

你好,斯蒂芬和福瑞文

谢谢你的帮助。我使用了alt+tab方法来解决这个问题,尽管我需要确保我在alt+tab键击时得到记事本,否则它会转到另一个应用程序。下面的示例解决了这个问题

Gui,添加,按钮,x22 y20 w120 h40,标题
Gui,添加,按钮,x22 y70 w120 h40,段落
Gui,显示,x152 y89 h131 w222,新Gui窗口
返回

钮扣:
发送!{Esc}
发送标题
返回

按钮标签:
发送!{Esc}
发送段落
返回

GuiClose:

ExitApp

当你点击你的GUI按钮时-猜猜哪一个是你的活动窗口(文本将被发送到的窗口)?可能是杀伤力过大(虽然看起来像一个干净的解决方案)(同样未经测试:{ALT}-{TAB}应该切换到最后一个活动窗口)很好!由于Alt+Tab可以计算出来,甚至可能有一个WinAPI函数返回最后一个活动窗口。