Send Keys question

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
2footer
Newbie
Posts: 3
Joined: Wed Jan 16, 2013 1:46 am

Send Keys question

Post by 2footer » Thu Jan 17, 2013 4:59 am

I current have a vbscript section of my macro that is intended to press AltF and then press x to exit the screen. When testing, sometimes it closes the screen and sometimes the X is not triggered. Is there a different way to configure this send key?


ws.SendKeys "%{F}"
ws.SendKeys "x"

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Thu Jan 17, 2013 7:41 am

Why are you doing that with VBScript. The best way would just be:

Press Alt
Send>fx
Release ALT

Split the f and x up if needed, or move the x outside the alt (all apps work differently) and insert a wait if needed. E.g.

Press Alt
Send>f
Release Alt
Wait>0.5
Send>x
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

2footer
Newbie
Posts: 3
Joined: Wed Jan 16, 2013 1:46 am

VB Script

Post by 2footer » Thu Jan 17, 2013 1:12 pm

Hello.

The reason the commands were in vbscript is because I needed to reactivate a window so I could close the program with the commands. I was using the appactivate command in vbscript to do this.

This is the whole vbscript function:
Function CloseApps
Dim ws
Set ws = CreateObject( "WScript.Shell" )
ws.AppActivate "Session"
Wscript.sleep 2000
ws.SendKeys "{F3}"
Wscript.sleep 2000
ws.SendKeys "90"
Wscript.sleep 2000
ws.SendKeys "{Enter}"
Wscript.sleep 1000
'ws.SendKeys "%{F}"
'ws.SendKeys "x"

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Thu Jan 17, 2013 1:17 pm

You don't need to use VBScript to activate a window. Just use the SetFocus command. E.g.:

SetFocus>Session
Wait>1
Press F3
Wait>2
Send>90
etc
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts