Jump to content

WshShell.SendKeys won't work


Recommended Posts

Hi,

VBS question:

I open the program and bring it to front, then pressing CTRL+TAB desired operation occurs.

When I try to replicate actions / macro via vbs script with iswindowactive followed by sendkeys it doesn't work.

Research suggests CTRL+TAB is equivalent to WshShell.SendKeys "^+({TAB})" but nope it doesn't work.

Also tried WshShell.SendKeys "^({TAB})" and nothing.

Set WshShell = CreateObject("WScript.Shell")
WshShell.Run """%PROGRAMFILES%\Folder\App.exe""" < this works
    WScript.Sleep 1000 < allows time to load
Set WshShell = WScript.CreateObject("WScript.Shell")
IsWindowActive = WshShell.AppActivate("Audio Control Panel")
If IsWindowActive Then
    WScript.Sleep 1000
    WshShell.SendKeys "^+{TAB}" < movement is seen on the buttons of window, but it is not the desired one.
End If

Any clues?

 

 

Edited by shorterxp
Link to comment
Share on other sites


The code "^+{TAB}" doesn't look like valid.

The "^" means CTRL, but the "+" means SHIFT:

https://msdn.microsoft.com/en-us/vba/language-reference-vba/articles/sendkeys-statement

The  "^({TAB})" seems correct :unsure: though braces shouldn't be needed, i.e. "^{TAB}"

Sendkeys is very tricky, and has often timing issues, maybe the 1000 is too low.

In this example, 5000 is used:

https://filedb.experts-exchange.com/incoming/2011/01_w02/386787/Cycle-And-Reload.txt

jaclaz

Link to comment
Share on other sites

This worked once! then never again!! The timer isn't a problem, 1000 or 5000 its the same, ctrl doesn't register.

 

I've read online that this is unfortunately a inhernant problem with VBS. SendKeys just isn't reliable.

 

What I want to do is open a .exe but on a specific TAB. This is not a browser tab but a set of options in tabular form.

I wonder if there is anyway to do with with a shortcut in windows XP?

 

Edited by shorterxp
Link to comment
Share on other sites

Autoit usually works fine, but of course you need to either compile the script or install the program.

Since Send in itself can in some cases be not reliable, they also have a controlsend, said to be more reliable:

https://www.autoitscript.com/autoit3/docs/functions/Send.htm

https://www.autoitscript.com/autoit3/docs/functions/ControlSend.htm

jaclaz

Link to comment
Share on other sites

Thanks

There is a command line utility called sendkeys.exe written by Orlando Magalhaes Filho. It accepts similar commands, the documentation says it can be invoked from VBS, CMD and LNK (shortcut). So far it looks promising but how do I invoke an executable to a .LNK? Target Box? with sendkeys.exe in als o working directory The documentaiton gives no examples - I emailed the dev no reply yet.

 

With sendkeys.exe you can define a delay prior to key strokes too which is ideal.

 

The goal is to activate a shortcut (by using a keyboard shortcut - a feature of .LNK files) and then that shortcut starts sendkeys.exe alongside the desired applet.exe.

 

 

Edited by shorterxp
Link to comment
Share on other sites

20 minutes ago, shorterxp said:

The goal is to activate a shortcut (by using a keyboard shortcut - a feature of .LNK files) and then that shortcut starts sendkeys.exe alongside the desired applet.exe.

Hmmm. :dubbio:

The goal is seemingly to use a shortcut (special key combo pressed on the keyboard) and that should open a given app and switch its windows to another tab.

The use of a .LNK file is some means to the goal that you believe is a suitable one.

If the goal is confirmed, I would rather use AutoHotKey (that has AFAICR very good provisions to send keys to programs):

https://autohotkey.com/docs_1.0/commands/Send.htm

and - as the name says - can be invoked/started with a hot key.

 

If you want to use sendkeys.exe with a shortcut:

http://cpap.com.br/orlando/SendKeysMore.asp

you will need to make a batch file (or a VB script) that first runs the "target" app and then runs sendkeys.exe and point the shortcut to the script.

jaclaz

Link to comment
Share on other sites

Grazie

=========================================================================

Edit AHK works perfectly, I made a notepad file contaning

Run, CTAudCSA.exe
Sleep, 750
IfWinExist Audio Control Panel
WinActivate
send ^{TAB}

Then used "Ahk2EXE.exe" to convert it to .exe, - this can now be executed from shortcut.

My only complaint is its 808kb footprint!

Now when I press a key, this opens shortcut, runs the Script above, the result: :thumbup

xfi.png

Luckily when the program is installed OptimumX shortcut.exe utility allows user to define Hotkey with /H:<keyboard numeric value>. I used 145 which is Scroll Lock.

shortcut /a:c /f:"%allusersprofile%\start menu\programs\Auzentech\Control Panel.lnk" 
/t:"%programfiles%\Auzentech\X-Fi Forte 7.1\AudioCS\AutoMode.exe" 
/w:"%programfiles%\Auzentech\X-Fi Forte 7.1\AudioCS" 
/i:"%programfiles%\Auzentech\X-Fi Forte 7.1\AudioCS\CTAudCSA.exe" 
/h:145

Heres a list of keyboard numeric vlues: http://virtuawin.sourceforge.net/?page_id=171.

 

I'm new to coding world, free command line utilities can be powerful.

Edited by shorterxp
Link to comment
Share on other sites

15 hours ago, shorterxp said:

Then used "Ahk2EXE.exe" to convert it to .exe, - this can now be executed from shortcut.

My only complaint is its 808kb footprint!

 

Yep :), that is a common issue with "compilers" (like the AutoHotKey one) that are essentially an assembly of the interpreter .exe + the actual script.

Since your script is extemely simple, maybe (it has to be tested) it will work with AutoHotKey v.1.0 (once called "Basic") that should allow to make .exe's in the around 200-300 KB size range.

jaclaz

Link to comment
Share on other sites

202KB Thanks ;)

rr.png

Mode changer needs extras installed notebaly console launcher, a skinned control panel. I did try it before but prefer this new HotKey method (a good compromise)

On a clean install, my WinRAR SFX quickly installs control panel and drivers only. I ran original 280mb Installer by Creative (InstallShield), monitored registry changes with InstallWatchPro (by Gavin Stark) then exported changes to .txt use in SFX setup...

Some of entries contained therein define absolutes i.e. "C:\". For security, I used Find And Replace Text utility replaces all instances of "C:\" to current drive (which may not be C at time of install). Windows Move command then converts that .txt back to .reg during setup, resultant .reg is imported silently. Here is example of setup.cmd inside SFX installer:

Quote

PF.exe
PUSHD "%allusersprofile%\start menu\programs"
md Auzentech
POPD
shortcut /a:c /f:"%allusersprofile%\start menu\programs\Auzentech\Control Panel.lnk" /t:"%programfiles%\Auzentech\X-Fi Forte 7.1\AudioCS\AutoMode.exe" /w:"%programfiles%\Auzentech\X-Fi Forte 7.1\AudioCS" /i:"%programfiles%\Auzentech\X-Fi Forte 7.1\AudioCS\CTAudCSA.exe" /H:145
fart -c --count install.txt C:\ %systemdrive%\
delay.vbs
move install.txt install.reg
delay.vbs
regedit /s install.reg
@ECHO Do not close / wait for setup to finish!
Setup.exe

People miss the fact that inside creative XP driver pack, usually in 'Driver' folder theres a setup.exe, which installs drivers only. Not sure if equivalent exists for win 7 (which uses UAA not WDM). The setup.exe dialog looks like this:

untitled.png

Example of custom SFX:

files1.png

Edited by shorterxp
Link to comment
Share on other sites

I'm really diggin the new hotkey, so fluid and easy to use, wouldn't have been possible without msfn!

TBH I'm surprised creative didn't make the modes tab the first one that shows.... oh well.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...