Is there a command for batch codes to change to another specific window? -
is possible put command batch file enter text specified window , hit enter key if user interacting it?
i know of handy little exe command prompt called "keystuff" capable of changing windows , inserting text, cant find has capability specify window change since utilizes alt+tab change window.
you can, sort of -- not entirely reliably, , not pure batch. can use wscript.shell
com object both appactivate
, sendkeys
methods. appactivate
let change focus window either pid or title. when focusing window title, match first attempted full title, title beginning, title ending, in order. so, example, if wanted send keystrokes firefox, shellobj.appactivate('firefox')
(because firefox tabs end in "mozilla firefox").
unfortunately, there's no easy way specify part of window gets focus. if want sendkeys
url bar search bar last focused before window last blurred, keys sent search bar. there's no way around unless simulate keyboard navigation (something ctrl+f focus find-in-page, tab 4 times focus url bar). can little messy.
caveats aside, here's example batch + jscript hybrid script (save .bat extension) demonstrating both appactivate
, sendkeys
methods. see sendkeys
technet article cheat sheet of symbols , meanings (such ~
sending enter).
@if (@codesection == @batch) @then @echo off setlocal if "%~2"=="" ( echo usage: %~nx0 "window title" "keys send" echo see https://technet.microsoft.com/en-us/library/ee156592.aspx goto :eof ) cscript /nologo /e:jscript "%~f0" "%~1" "%~2" goto :eof @end // end batch / begin jscript chimera var osh = wsh.createobject('wscript.shell'), args = { title: wsh.arguments(0), keys: wsh.arguments(1) }; function type(what) { var keys = what.split('{pause}'); (var i=0; i<keys.length;) { osh.sendkeys(keys[i]); if (++i < keys.length) wsh.sleep(500); } } osh.appactivate(args.title); type(args.keys);
using script, if enter
scriptname.bat "firefox" "^f{bs}{pause}{tab 4}{pause}http://www.google.com~{pause}^f{esc}"
... you'll focus firefox, send ctrl+f open or focus find-in-page, backspace erase existing search string, tab url bar, navigate google, close find-in-page footer bar.
see? told you. messy. doable.
Comments
Post a Comment