AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Error send keys to foreground window

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
GreatKent



Joined: 05 Oct 2004
Posts: 20

PostPosted: Sat Mar 12, 2005 6:07 am    Post subject: Error send keys to foreground window Reply with quote

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!! Very Happy


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
View user's profile Send private message
Serenity



Joined: 08 Nov 2004
Posts: 1230

PostPosted: Sat Mar 12, 2005 6:17 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
GreatKent



Joined: 05 Oct 2004
Posts: 20

PostPosted: Sat Mar 12, 2005 7:00 am    Post subject: Reply with quote

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
View user's profile Send private message
jonny



Joined: 13 Nov 2004
Posts: 3004
Location: Minnesota

PostPosted: Sat Mar 12, 2005 7:08 am    Post subject: Reply with quote

This should work:

Code:
^enter::send,^a^c


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
View user's profile Send private message
Serenity



Joined: 08 Nov 2004
Posts: 1230

PostPosted: Sat Mar 12, 2005 7:09 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
jonny



Joined: 13 Nov 2004
Posts: 3004
Location: Minnesota

PostPosted: Sat Mar 12, 2005 7:11 am    Post subject: Reply with quote

Serenity: Send usually sends to the active window, you don't have to hard-code it.
Back to top
View user's profile Send private message
Serenity



Joined: 08 Nov 2004
Posts: 1230

PostPosted: Sat Mar 12, 2005 7:11 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
jonny



Joined: 13 Nov 2004
Posts: 3004
Location: Minnesota

PostPosted: Sat Mar 12, 2005 4:32 pm    Post subject: Reply with quote

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
View user's profile Send private message
Serenity



Joined: 08 Nov 2004
Posts: 1230

PostPosted: Sat Mar 12, 2005 6:16 pm    Post subject: Reply with quote

Thanks Jonny. Smile

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
View user's profile Send private message Visit poster's website
GreatKent



Joined: 05 Oct 2004
Posts: 20

PostPosted: Sun Mar 13, 2005 3:17 am    Post subject: Reply with quote

Hi jonny, thank you very much! Very Happy the code work perfectly for me, it's neat and awesome! Laughing


jonny wrote:
This should work:

Code:
^enter::send,^a^c


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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group