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 

what am I doing wrong... send text to notepad?

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



Joined: 15 May 2009
Posts: 12

PostPosted: Fri May 15, 2009 5:30 pm    Post subject: what am I doing wrong... send text to notepad? Reply with quote

Hi all,

I'm writing my first script.
-------
Run, Notepad.exe, C:\My Documents, max
IfWinExist, Notepad
{
WinActivate
SendInput, Dude, what the hell. this is notepad
}
------

What I get is notepad opens, but there is no text being sent to notepad.
What am I missing here?

I have tried Send instead of SendInput
I have also tried to setfocuscontrol.

I am sure it is a simple thing.

Thanks,
Back to top
View user's profile Send private message
scott257us



Joined: 01 Jul 2008
Posts: 34
Location: Ohio

PostPosted: Fri May 15, 2009 5:47 pm    Post subject: Try this work good for me Reply with quote

Code:
DetectHiddenText, On
SetTitleMatchMode 2
SetTitleMatchMode Slow


Run, Notepad.exe, C:\My Documents, max
WinWaitActive, Notepad
SendInput, Dude, what the hell. this is notepad



It works pretty fast and is very slick.
Back to top
View user's profile Send private message
Guest






PostPosted: Fri May 15, 2009 5:47 pm    Post subject: Re: what am I doing wrong... send text to notepad? Reply with quote

scamper_22 wrote:
Hi all,

Run, Notepad.exe, C:\My Documents, max
IfWinExist, Notepad
{
WinActivate - Notpad
SendInput, Dude, what the hell. this is notepad
}
return
Back to top
Guest23
Guest





PostPosted: Fri May 15, 2009 5:48 pm    Post subject: Reply with quote

your title is not correct...: IfWinExist, Notepad

Open up Notepad manually and see what the window title is.
Back to top
badmojo



Joined: 11 Nov 2005
Posts: 202

PostPosted: Fri May 15, 2009 5:49 pm    Post subject: Reply with quote

try this:
Code:

SendMode, Input
SetTitleMatchMode 2

Run, notepad.exe, C:\My Documents, max
WinWait, Notepad
if ErrorLevel <>
{
WinActivate
Send, Dude, what the hell. this is notepad 
}


Last edited by badmojo on Fri May 15, 2009 6:23 pm; edited 1 time in total
Back to top
View user's profile Send private message
anon
Guest





PostPosted: Fri May 15, 2009 6:03 pm    Post subject: Reply with quote

You should wait fot the Notepad window to be created before sending keys to it. The help file for Run says:
Quote:
After the Run command retrieves a PID, any windows to be created by the process might not exist yet. To wait for at least one window to be created, use WinWait ahk_pid %OutputVarPID%


This works reliably:
Code:
run, Notepad.exe, C:\My Documents, max, notePadPID
WinWait, ahk_pid %notepadPID%WinActivate
SendInput, Dude, what the hell. this is notepad
Back to top
anon
Guest





PostPosted: Fri May 15, 2009 6:06 pm    Post subject: Reply with quote

hmm, had a paste problem...
Code:
run, Notepad.exe, C:\My Documents, max,notePadPID
WinWait, ahk_pid %notepadPID%
WinActivate
SendInput, Dude, what the hell. this is notepad
Back to top
scamper_22



Joined: 15 May 2009
Posts: 12

PostPosted: Fri May 15, 2009 6:18 pm    Post subject: Reply with quote

anon,

no, I tried that (exactly copied and pasted)... still no text in notepad.

Right now it is in this state:
--------------
DetectHiddenText, On
SetTitleMatchMode 2
SetTitleMatchMode Slow

run, Notepad.exe, C:\My Documents, max,notePadPID
WinWait, ahk_pid %notepadPID%
WinActivate
SendInput, Dude, what the hell. this is notepad
return
--------------

I am trying this at work. Is it possible there is some security thing blocking this? Running Windows XP SP3 with Semantic Endpoint Protection... ?

Thanks
Back to top
View user's profile Send private message
scamper_22



Joined: 15 May 2009
Posts: 12

PostPosted: Fri May 15, 2009 6:22 pm    Post subject: this kind of works.... Reply with quote

badmojo's one works. For some reason

The top two lines of his scrpit would not work
---
SendMode, Input, C:\My Documents, max
---

So I ran this:
-----
Run, notepad.exe
WinWait, Notepad, , 3
if ErrorLevel <>
{
WinActivate
Send, Dude, what the hell. this is notepad
}
----
It creates a new notepad window
but then sends the text to my notepad++ window Razz
Back to top
View user's profile Send private message
badmojo



Joined: 11 Nov 2005
Posts: 202

PostPosted: Fri May 15, 2009 6:25 pm    Post subject: Reply with quote

sorry just realised that i had pasted in the wrong place.. it should be just

Code:
SendMode, Input


i had edited the above post and corrected it. Smile
Back to top
View user's profile Send private message
scamper_22



Joined: 15 May 2009
Posts: 12

PostPosted: Fri May 15, 2009 6:26 pm    Post subject: okie... this works now... Reply with quote

---

SetTitleMatchMode 2

Run, notepad.exe
;WinWait, Notepad, , 3
WinWait , Notepad, , 3, ++,
if ErrorLevel <>
{
WinActivate
Send, Dude, what the hell. this is notepad
}
----

I exclude notepad++ with the ++ exclude title variable.
Back to top
View user's profile Send private message
sinkfaze



Joined: 18 Mar 2008
Posts: 5044
Location: the tunnel(?=light)

PostPosted: Fri May 15, 2009 6:26 pm    Post subject: Reply with quote

Try this:

Code:
Run, Notepad.exe
WinWait, ahk_class Notepad
WinActivate, ahk_class Notepad
ControlSend, Edit1, what the hell. this is notepad, ahk_class Notepad
return

_________________
Try Quick Search for Autohotkey or see the tutorial for newbies.
Back to top
View user's profile Send private message Send e-mail
scamper_22



Joined: 15 May 2009
Posts: 12

PostPosted: Fri May 15, 2009 6:29 pm    Post subject: Reply with quote

Thanks for the help guys.

Badmojo... just for record, the issue with my original script was that it was not waiting for the window to come up? The ifwinexist would check before the window came up and it would not execute the send.

correct?
Back to top
View user's profile Send private message
badmojo



Joined: 11 Nov 2005
Posts: 202

PostPosted: Fri May 15, 2009 6:35 pm    Post subject: Reply with quote

@scamper_22: yes the 'IfWinExist' only checks if the specified window already exists. if there was a delay, then it'd skip over to the next line.
Back to top
View user's profile Send private message
Display posts from previous:   
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