Greetings,
I'm new to AHK and programming so please bear with me as I struggle to get through the various learning curves.
I'm trying to develop an application with AHK that allows a user to send a text string to an application. I've developed an interface that allows the user to select options that determines what text to send and input variables for the text string.
There are a few challenges for me here, mainly with getting the app to send the text to the right application, in the right spot. The closest thing I've found here on the forums is a post by shimanov >
http://www.autohotkey.com/forum/topic6795.html where he uses ControlGetFocus and ControlSendRaw to accomplish something similar.
Here are the problems I'm having and I really hope someone here can start me in the right direction:
1. I can't get shiminov's method to work in my code.
2. Although I'm unable to get it to work with my code, I've tested his and I noticed that after the text is inputted in the last active control, I have to manually activate the window to continue typing in that control. I'd like to be able to start typing without having to manually activate the window
3. I'd like to be able to send multiple strings to the last active control. If you run my app, you'll see that you can select different strings. Lets say you select "script1" to send, click "Sendtxt" and then select a different script (or even the same) and click "Sendtxt" again. If you run, shiminov's script, you'll find that selecting "Insert Name" twice in a row does not work. My concern is that by selecting different tabs in my interface, or making selections in menu, the application loses track of the target control.
4. The text input speed with ControlSendRaw seems somewhat slow. Is there anyway to speed this up?
5. Lastly, is shiminov's method the best for my application?
My Code:
Code:
Gui +AlwaysOnTop +ToolWindow
Gui, Add, Tab, x3 y-3 w240 h560 0x80 0x200 +Left, Scripts|DBlookups|Reports|Acq|Display|Wkstn|Perf|Audit|Send|Rep|BigIP|RAID|*nix|Backups|Print|Processes|Logs|Network|DevConfig|Version|SNMP|Sybase|Hosts|Links|
Gui, Tab, Scripts
Gui, Add, DropDownList, x73 y57 w100 h21 R3 vVersions, 1.x||2.x|3.x
Gui, Add, Button, x73 y17 w100 h30 , isql and version
Gui, Add, DropDownList, x73 y87 w100 h21 R3 vVartypes, varchar||integer
Gui, Add, Button, x183 y17 w50 h140 , SendTxt
Gui, Add, Edit, x73 y117 w100 h50 vVariables, input variables here
Gui, Add, Progress, x183 y157 w50 h10 , 25
Gui, Add, Button, x183 y227 w50 h40 +, Modify
Gui, Add, Button, x183 y277 w50 h40 , Add
Gui, Add, Button, x183 y327 w50 h40 , Delete
Gui, Add, Button, x183 y177 w50 h40 , view script
Gui, Add, Button, x183 y377 w50 h40 , Save
Gui, Add, Button, x183 y427 w50 h40 , Set Default
Gui, Add, ListBox, x73 y177 w100 h360 0x800 vScripts, Script1|Script2|Script3
; Generated using SmartGUI Creator 4.0
Gui, Show, x368 y151 h560 w248, SENDTEXT CONSOLE
Return
WM_USER = 0x400
AHK_NOTIFYICON := WM_USER+4
OnMessage( AHK_NOTIFYICON, "HandleMessage" )
HandleMessage( p_w, p_l )
{
global hw_last_active, control_last_active, hold_last_active
; WM_MOUSEMOVE
if ( p_l = 0x200 and ! hold_last_active )
{
WinGet, hw_last_active, ID, A
ControlGetFocus, control_last_active, ahk_id %hw_last_active%
}
; WM_RBUTTONDOWN
else if ( p_l = 0x204 )
{
hold_last_active := true
}
}
ButtonSendTxt:
Gui, submit, noHide
if (Versions="1.x" and Vartypes="varchar")
{
ControlSendRaw, %control_last_active%, selected %versions% and %varchar% , ahk_id %hw_last_active%
}
hold_last_active := false
return
Gui, Show
Return
GuiClose:
ExitApp
Shiminov's code:
Code:
WM_USER = 0x400
AHK_NOTIFYICON := WM_USER+4
OnMessage( AHK_NOTIFYICON, "HandleMessage" )
Menu, Tray, NoStandard
Menu, Tray, Add, Insert Name, InsertName
Menu, Tray, Add
Menu, Tray, Standard
return
HandleMessage( p_w, p_l )
{
global hw_last_active, control_last_active, hold_last_active
; WM_MOUSEMOVE
if ( p_l = 0x200 and ! hold_last_active )
{
WinGet, hw_last_active, ID, A
ControlGetFocus, control_last_active, ahk_id %hw_last_active%
}
; WM_RBUTTONDOWN
else if ( p_l = 0x204 )
{
hold_last_active := true
}
}
InsertName:
ControlSendRaw, %control_last_active%, 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111, ahk_id %hw_last_active%
hold_last_active := false
return
Look forward to your responses!
Z