AutoHotkey Community

It is currently May 26th, 2012, 7:49 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 14 posts ] 
Author Message
PostPosted: May 15th, 2009, 6:30 pm 
Offline

Joined: May 15th, 2009, 6:26 pm
Posts: 12
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,


Report this post
Top
 Profile  
Reply with quote  
PostPosted: May 15th, 2009, 6:47 pm 
Offline

Joined: July 1st, 2008, 8:57 pm
Posts: 34
Location: Ohio
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.


Report this post
Top
 Profile  
Reply with quote  
PostPosted: May 15th, 2009, 6:47 pm 
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


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: May 15th, 2009, 6:48 pm 
your title is not correct...: IfWinExist, Notepad

Open up Notepad manually and see what the window title is.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: May 15th, 2009, 6:49 pm 
Offline

Joined: November 11th, 2005, 3:13 am
Posts: 202
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 May 15th, 2009, 7:23 pm, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 15th, 2009, 7:03 pm 
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


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: May 15th, 2009, 7:06 pm 
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


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: May 15th, 2009, 7:18 pm 
Offline

Joined: May 15th, 2009, 6:26 pm
Posts: 12
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject: this kind of works....
PostPosted: May 15th, 2009, 7:22 pm 
Offline

Joined: May 15th, 2009, 6:26 pm
Posts: 12
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 :P


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 15th, 2009, 7:25 pm 
Offline

Joined: November 11th, 2005, 3:13 am
Posts: 202
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. :)


Report this post
Top
 Profile  
Reply with quote  
PostPosted: May 15th, 2009, 7:26 pm 
Offline

Joined: May 15th, 2009, 6:26 pm
Posts: 12
---

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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 15th, 2009, 7:26 pm 
Offline
User avatar

Joined: March 19th, 2008, 12:43 am
Posts: 5480
Location: the tunnel(?=light)
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

_________________
Image
Try Quick Search for Autohotkey or see the tutorial for newbies.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 15th, 2009, 7:29 pm 
Offline

Joined: May 15th, 2009, 6:26 pm
Posts: 12
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?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 15th, 2009, 7:35 pm 
Offline

Joined: November 11th, 2005, 3:13 am
Posts: 202
@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.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 14 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: 0x150||ISO, Azevedo, perlsmith and 69 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group