s := VarSetCapacity(a, 4096)
loopcount := 5
myhotkey := "F"5
Gosub,Read
Gosub,TrayMenu
Gosub,Settings
Return
Read:
If myhotkey Not In F1,F2,F3,F4,F5,F6,F7,F8,F9,F10,F11,F12
,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z
,а,б,в,г,д,е,ё,ж,з,и,й,к,л,м,н,о,п,р,с,т,у,ф,х,ц,ч,ш,щ,ъ,ы,ь,э,ю,я
,1,2,3,4,5,6,7,8,9,0,-,=,*,/,\,[,]
{
myhotkey := "F"5
Gosub, Settings
}
If myhotkey =
{
myhotkey := "F"5
Gosub, Settings
}
If (loopcount = "0" || loopcount = "")
{
loopcount := 5
Gosub, Settings
}
hotkeydown = *%myhotkey%
Hotkey, %hotkeydown%, HotkeyLabel, On
Return
HotkeyLabel:
Loop, % loopcount
{ ; собственно это переработанный 4тый пример из описания по комманде Process
DllCall("Psapi.dll\EnumProcesses"
, "UInt", &a
, "UInt", s
, "UIntP", r)
Loop, % r // 4
{
id := NumGet(a, A_Index * 4)
h := DllCall("OpenProcess"
, "UInt", 0x0010 | 0x0400
, "Int", false
, "UInt", id)
VarSetCapacity(n, 4096, 0)
e := DllCall("Psapi.dll\GetModuleBaseNameA"
, "UInt", h
, "UInt", 0
, "Str", n
, "UInt", s)
DllCall("CloseHandle", "UInt", h)
If (n && e && n = "mstsc.exe")
{
; WinActivate, % "ahk_pid" id ; вариант 1 - активация всех найденых окон
WinWaitActive, % "ahk_pid" id ; вариант 2 - ожидание активации найденых окон
Send, {Enter}
}
}
}
KeyWait, % myhotkey
Return
SettingsOK:
Gui, Submit
Gosub, Read
Return
Settings:
Hotkey, %hotkeydown%, HotkeyLabel, Off
Gui, Destroy
Gui, Font, Courier New
Gui, Add, Edit, vmyhotkey x12 y10 w20 h20 , % myhotkey
Gui, Add, Edit, vloopcount x12 y40 w20 h20 , % loopcount
Gui, Add, Button, gSettingsCancel x72 y70 w50 h20 , &Cancel
Gui, Add, Text, x42 y10 w100 h20 , choose desired key
Gui, Add, Text, x42 y40 w140 h20 , select count of loops
Gui, Add, Button, gSettingsOK x12 y70 w50 h20 , &OK
Gui, Add, Button, gExit x132 y70 w50 h20 , &Exit
Gui, Show, Center h106 w187, Settings
Return
TrayMenu:
Menu, Tray, NoStandard
Menu, Tray, Add, &Settings, Settings
Menu, Tray, Add, &About, About
Menu, Tray, Add, &Exit, Exit
Return
SettingsCancel:
Gui, Destroy
Hotkey, %hotkeydown%, HotkeyLabel, On
GuiClose: ; закрыть на крестик не получится, надо делать выбор: ок, отмена или выход :)
Return
About:
Gui, 99:Font, CBlue Underline
Gui, 99:Add, Text, y+5 gGoAutoHotKey, www.autohotkey.com
Gui, 99:Font
Gui, 99:+AlwaysOnTop
Gui, 99:Show, Center
Return
GoAutoHotKey:
Run, http://www.autohotkey.com,, UseErrorLevel
Return
Exit:
Gui, Destroy
ExitApp