 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
z3lig
Joined: 13 Aug 2007 Posts: 11
|
Posted: Wed Aug 15, 2007 12:14 pm Post subject: Send text to last active control in last active window |
|
|
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 |
|
| Back to top |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 5887
|
Posted: Wed Aug 15, 2007 1:30 pm Post subject: |
|
|
Download and try AHKOSK Onscreen Keyboard.
That app inputs to a target window without taking the focus off
Are you seeking similar functionality ?
 |
|
| Back to top |
|
 |
z3lig
Joined: 13 Aug 2007 Posts: 11
|
Posted: Wed Aug 15, 2007 6:08 pm Post subject: |
|
|
Oh my. Yes, it seems so. I'll now have to see how micha accomplished this - seems like this may be over my head but I'm certainly up for the challenge.
Thanks for the tip. Z |
|
| Back to top |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 5887
|
Posted: Wed Aug 15, 2007 6:15 pm Post subject: |
|
|
| z3lig wrote: | | I'll now have to see how micha accomplished this |
Not Micha .. Micahs. The source code does not seem exist in the download .. Maybe you can PM him.
 |
|
| Back to top |
|
 |
engunneer
Joined: 30 Aug 2005 Posts: 6772 Location: Pacific Northwest, US
|
Posted: Wed Aug 15, 2007 6:35 pm Post subject: |
|
|
The source code was included in the download last I checked... _________________
Unless otherwise noted, all code is untested.
Common Answers: 1.(Loops, Viruses, etc.) 2. Search 3.RTFM |
|
| Back to top |
|
 |
z3lig
Joined: 13 Aug 2007 Posts: 11
|
Posted: Wed Aug 15, 2007 7:19 pm Post subject: |
|
|
| No, the source was not in the last distribution. |
|
| Back to top |
|
 |
engunneer
Joined: 30 Aug 2005 Posts: 6772 Location: Pacific Northwest, US
|
|
| Back to top |
|
 |
Micahs
Joined: 01 Dec 2006 Posts: 338
|
Posted: Thu Aug 16, 2007 5:58 am Post subject: |
|
|
The source code is back in the zip. Sorry! I was compiling for a friend and forgot to add the source. I took the exe out. Thanks for noticing!
If you want a hand, give a holler! _________________
 |
|
| Back to top |
|
 |
z3lig
Joined: 13 Aug 2007 Posts: 11
|
Posted: Thu Aug 16, 2007 8:19 am Post subject: |
|
|
Micahs/All,
Thank you very much for your support.
Micahs,
I've reviewed your source and believe I understand it in concept (you're intercepting the mouse events to keep focus on the target app - I apologize if this is an oversimplification) but before I try to implement your solution, I wanted to try using timers with WinGet to get the active window every 100ms. If the active window id is different from my application's id, I send a WinActivate to that id and perform a SendInput.
Unfortunately, this is not working for me and would like to solicit help from the forums.
Code attached. Thanks in advance. Z
| Code: |
Gui +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
settimer GetBamID, 100 ; set timer to fetch ahk app's id every 100ms
settimer GetActiveID, 100 ; set timer to fetch active window id every 100ms
;function to get id of ahk application based on window title of "SENDTEXT"
GetBamID:
WinGet, SendTextID, ID, SENDTEXT
return
;function to get id of active window
GetActiveID:
WinGet, Active_ID, ID, A
return
;store id of last active window and make sure it isn't SendText's ID
if (%Active_ID% != %SendTextID%)
{
Active_ID2 = %Active_ID%
}
return
ButtonSendTxt:
{
Gui, Submit, noHide
if (%Active_ID2% = %BamID%)
{
MsgBox, Active ID2 %Active_ID2%, Active ID %Active_ID%, BamID %BamID%
}
else if (Versions="1.x" and Vartypes="varchar")
{
WinActivate, ahk_id %Active_ID2% ;activate last active window
WinWaitActive, ahk_id %Active_ID2% ;wait for last active window
SendInput,%Versions% and %Vartypes%
}
}
Gui, Show
Return
GuiClose:
ExitApp
|
|
|
| Back to top |
|
 |
z3lig
Joined: 13 Aug 2007 Posts: 11
|
Posted: Thu Aug 16, 2007 7:17 pm Post subject: |
|
|
Hello, Again,
I was able to find a similar solution here:
http://www.autohotkey.com/forum/viewtopic.php?t=4234&start=0&postdays=0&postorder=asc
But I'm still having difficulty putting it all together. I realize this thread is getting a bit lengthy for what I need so I'll try to summarize:
At this point, I'd like to apply to my gui, see above, the ability to detect the last active window (or input control) by monitoring active window every 100ms. If the id returned by the timer does not equal the id of my AHK app, I will know that that is the value I should use to send the text to. |
|
| Back to top |
|
 |
z3lig
Joined: 13 Aug 2007 Posts: 11
|
Posted: Fri Aug 17, 2007 11:16 am Post subject: |
|
|
finally figured it out but for some reason the edit control envokes its own ahk_id when you input text. dropdown, buttons do not do this. Anyone know how I can work-around this? Also, is this by design?
| Code: |
Gui +AlwaysOnTop
Gui, Add, Edit, x73 y27 w280 h90 , Edit
Gui, Add, Button, x163 y247 w100 h40 gSendInput, getids
; Generated using SmartGUI Creator 4.0
Gui, Show, x179 y229 h301 w429, App
SetTimer, WindowIDs, 100
WinGet, AppID, ID, App
WindowIDs:
WinGet, Targetwin, ID, A
if AppID <> %Targetwin%
{
PreviousWin = %Targetwin%
}
return
SendInput:
Gui, Submit, NoHide
{
;WinActivate, ahk_id %PreviousWin%
;WinWaitActive, ahk_id %PreviousWin%
;SendInput, Good job. Previous Window %PreviousWin% and AppID %AppID%
MsgBox, AppID: %AppID%, PreviousWin: %PreviousWin%
}
return
GuiClose:
ExitApp
|
|
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|