| View previous topic :: View next topic |
| Author |
Message |
GreatKent
Joined: 05 Oct 2004 Posts: 20
|
Posted: Sat Mar 12, 2005 6:07 am Post subject: Error send keys to foreground window |
|
|
I am trying to detect Ctrl+Enter, then send Ctrl+A and Ctrl+C to the foreground window.
the following code can detect Ctrl+Enter, but the keys are NOT sent to foreground window! Could any body pls tell me what's been wrong with code?
BTW, is there better way to detect that BOTH Ctrl and Enter are pressed?
Thank a lots!!
| Code: |
;
; AutoHotkey Version: 1.x
; Language: English
; Platform: Win9x/NT
; Author: A.N.Other <myemail@nowhere.com>
;
; Script Function:
; Template AutoHotkey script.
;
#SingleInstance Ignore
Loop
{
KeyWait, Control, D
Loop
{
KeyWait, Enter, D, T1
GetKeyState, cont, Control, P
if(ErrorLevel = 1)
break
else
{
if(cont = "D")
{
Send, {CtrlDown}
Send, A
Send, C
Send, {CTRLUp}
break
}
else
break
}
}
}
|
|
|
| Back to top |
|
 |
Serenity
Joined: 08 Nov 2004 Posts: 1230
|
Posted: Sat Mar 12, 2005 6:17 am Post subject: |
|
|
If you want the keys to send to a particular window only when its active I find this method useful:
| Code: | ~^enter::
IfWinActive, targetwindow
{
Send, {^a}
sleep, 100
Send, {^c}
return
}
IfWinNotActive, targetwindow
Send, {^S}
return |
_________________ "Anything worth doing is worth doing slowly." - Mae West
 |
|
| Back to top |
|
 |
GreatKent
Joined: 05 Oct 2004 Posts: 20
|
Posted: Sat Mar 12, 2005 7:00 am Post subject: |
|
|
I am sorry you man misunderstood me a bit...
i mean sending keys to whatever window is active, not a particular one.
| Serenity wrote: | If you want the keys to send to a particular window only when its active I find this method useful:
| Code: | ~^enter::
IfWinActive, targetwindow
{
Send, {^a}
sleep, 100
Send, {^c}
return
}
IfWinNotActive, targetwindow
Send, {^S}
return |
|
|
|
| Back to top |
|
 |
jonny
Joined: 13 Nov 2004 Posts: 3004 Location: Minnesota
|
Posted: Sat Mar 12, 2005 7:08 am Post subject: |
|
|
This should work:
You might also want to check out the ControlGetText function, as it's very similar to pressing C-a and C-c, but you may find it too difficult to understand. Also, you'd definitely want to look at the quick-start tutorial if you haven't already. |
|
| Back to top |
|
 |
Serenity
Joined: 08 Nov 2004 Posts: 1230
|
Posted: Sat Mar 12, 2005 7:09 am Post subject: |
|
|
You can modify that script to first get the active window then send keys only to that, like so:
| Code: | ~^enter::
WinGetActiveTitle, targetwindow
IfWinActive, %targetwindow%
{
Send, {^a}
sleep, 100
Send, {^c}
return
}
IfWinNotActive, %targetwindow%
Send, {^S}
return |
_________________ "Anything worth doing is worth doing slowly." - Mae West
 |
|
| Back to top |
|
 |
jonny
Joined: 13 Nov 2004 Posts: 3004 Location: Minnesota
|
Posted: Sat Mar 12, 2005 7:11 am Post subject: |
|
|
| Serenity: Send usually sends to the active window, you don't have to hard-code it. |
|
| Back to top |
|
 |
Serenity
Joined: 08 Nov 2004 Posts: 1230
|
Posted: Sat Mar 12, 2005 7:11 am Post subject: |
|
|
It usually works Jonny, but not always. Which is why I wrote that code. _________________ "Anything worth doing is worth doing slowly." - Mae West
 |
|
| Back to top |
|
 |
jonny
Joined: 13 Nov 2004 Posts: 3004 Location: Minnesota
|
Posted: Sat Mar 12, 2005 4:32 pm Post subject: |
|
|
If it doesn't work as intended, it might be a bug in AutoHotkey. Can you reproduce a situation where Send doesn't send to the active window?
Btw, I love the new sig. |
|
| Back to top |
|
 |
Serenity
Joined: 08 Nov 2004 Posts: 1230
|
Posted: Sat Mar 12, 2005 6:16 pm Post subject: |
|
|
Thanks Jonny.
It might not be a bug. I think part of the problem is that I use the AlwaysOnTop feature alot in windows so its not always clear what the active window is. Another factor is that I like to use hotkeys that are already used by other applications. With some things I cannot afford to have the wrong key sent to the wrong window which is why I hardcode it per window rather than relying on it sending to the active window. I tend to use this approach for all my hotkeys now. (Control freak!) _________________ "Anything worth doing is worth doing slowly." - Mae West
 |
|
| Back to top |
|
 |
GreatKent
Joined: 05 Oct 2004 Posts: 20
|
Posted: Sun Mar 13, 2005 3:17 am Post subject: |
|
|
Hi jonny, thank you very much! the code work perfectly for me, it's neat and awesome!
| jonny wrote: | This should work:
You might also want to check out the ControlGetText function, as it's very similar to pressing C-a and C-c, but you may find it too difficult to understand. Also, you'd definitely want to look at the quick-start tutorial if you haven't already. |
|
|
| Back to top |
|
 |
|