Multiple programs boot and sendkeys alternative - windows

I'm trying to execute a VBScript by a Logitech UberOptions hotkey, but of course, because of the SendKeys numberlock bug, the nice little huge Logitech NumLock toggle graphic strews itself over my screen. It doesn't look pretty. I assume an alternative to SendKeys would remedy that.
However, a real problem exists when the vbs tries to boot 2 exe's. It properly launches WOMic AND Jarvis, but Jarvis force closes milliseconds after the boot, WOmic still remains.
The final line of code is where I "auto-connect" to my microphone server (on my android) through the menu bar of the WOMic GUI.
What's an alternative to SendKeys in this scenario?
Here is my script:
Set oShell = CreateObject("WScript.Shell")
oShell.Run("""C:\Program Files (x86)\JARVIS\CustomizeableJarvis.exe""")
WScript.Sleep 250
oShell.Run("""C:\Program Files (x86)\WOMic\womicclient.exe""")
WScript.Sleep 500
oShell.AppActivate "WO Mic Client 2.10"
WScript.Sleep 100
oShell.SendKeys "%cc~"

Totally forgot about this post, I suppose I can answer my own question now.
Anyone viewing this should just opt to use AutoHotKey. MUCH better to accomplish what I was trying to do.

Related

VBS Can't printscreen

I recently picked up VBScript and I was messing with the sendkey commands when I noticed that the {PRTSC} isn't working on my computer.
My Program: I made it so that it'll take a screenshot and paste it.
set objShell = CreateObject("WScript.Shell")
WScript.Sleep 1000
objShell.sendKeys "{prtsc}"
objShell.SendKeys "^V"
Is there something wrong with the code or am I not understanding something?
Thanks.
Note
You cannot send the PRINT SCREEN key {PRTSC} to an application.
From Help https://msdn.microsoft.com/fr-fr/library/8c6yea83(v=vs.84).aspx
Also Sendkeys is part of Windows Scripting Host not VBScript.

Create a VB script to send the keys to open up a program with specific settings

I am trying to create a VB script to send the keys to open up a program/application with specific settings. So, after the application has been started, choosing those very specific settings would involve pressing 2 buttons inside the application UI (1st button to choose specific set of options, and 2nd button to save those options).
I will then create a batch file to call the mentioned VB script on boot.
So far, I got this:
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.SendKeys "^%1"
I've searched and searched, but couldn't figure out how to be able choose/save options once the app has been started, if it's even possible?
Thank you in advance for helping out!
Disclaimer: I am not a technical person, so forgive me if noob question :)
Here's a script to start an application (notepad), then send some keystrokes to it:
'VBScript Example
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "c:\windows\notepad.exe"
' add delay here
WshShell.AppActivate "Notepad"
WshShell.SendKeys "Hello World!"
WshShell.SendKeys "{ENTER}"
WshShell.SendKeys "abc"
WshShell.SendKeys "{CAPSLOCK}"
WshShell.SendKeys "def"
Perhaps this can be adapted to your needs?
The WshShell.AppActivate command is used to bring the program (with the specified window title) to the foreground.
You might want to add a delay to allow the program time to start before sending the keystrokes. This can be done by adding a sleep() call just after Wshell.Run:
' Sleep for 5 seconds (5000 msec)
WScript.Sleep(5000)
Also, here's a list of key-codes that you can use.

WScript.Shell SendKeys not working on Windows 8.1 x64

I'm having problems with the following VBScript.
I'm trying to send keystrokes to a web browser window, but nothing happens.
The first two lines in the following script works fine, but the third line with the SendKeys command, doesn't do anything.
Set objShell = CreateObject("WScript.Shell")
objShell.Run "http://someurl.com", 1
objShell.SendKeys "Some Text"
I've tried to run the script on two different Win 8.1 machines. On Win 8.1 Pro it works, but on Win 8.1 not-Pro it won't work. Is there any setting somewhere in Windows that needs to be set or anything other that can help me?
Update
New code tried (added sleep and running browser explicit), but still no luck
Set ObjShell = WScript.CreateObject("WScript.Shell")
objShell.Run """C:\Program Files\Internet Explorer\iexplore.exe""http://someurl.com/"
WScript.Sleep 5000
objShell.SendKeys "Some Text"
While its admittedly not a great programming technique, place a Sleep command after your objShell.Run line (as shown below) to give the OS some time to "catch up" and actually run the URL, activate the browser window to give it focus (you have to take note of the title in the Browser window and use that title exactly), because I have seen the browser window lose focus in some cases and then text cannot be piped into it, and finally it sends the text. Your mileage may vary, and you might even have to increase the sleep time in order to be successful. I've had to sleep up to 30 seconds, in some cases. Especially where, for whatever reason, the web page was slow to render - due to network latency, slow OS, etc.. I haven't faced this problem on Windows 8.1 because I haven't tried it on that platform. I don't think this has anything to do with the OS version; I have faced this same problem with SendKeys on other Windows OS versions where I've had to use the Sleep function like this. The SendKeys method has known limitations, and as it runs outside of the browser you have to wait for certain actions to complete before you can have it do more actions.
Set ObjShell = WScript.CreateObject("WScript.Shell")
objShell.Run "http://someurl.com", 1
WScript.Sleep 20000
objShell.appactivate("Welcome to SOMEURL.COM! - Mozilla Firefox")
WScript.Sleep 700
objShell.SendKeys "Some Text"
Also, you might try replacing line 2 in the above to the following, to see if you have better luck. In the example below, Firefox is the default web browser. Change the path accordingly to the browser of your choice:
objShell.Run("""C:\Program Files\Mozilla Firefox\firefox.exe""http://someurl.com")

Simplest way to monitor 3rd party windows application for keystrokes

As the title says, what is the simplest way to monitor for specific keystrokes in a 3rd party windows application?
Background: Arcmap 10.2 is notorious for crashing. There is no built in autosave functionality whilst editing features so I am often losing data. While obviously the best approach is to remember to manually save my edits periodically I would like to know if I can automate this. I have been using a simple vbscript wrapper (see below) that sends the 'ctrl+alt+shift+S' keystroke (save edits keyboard shortcut) every 5 minutes. This alleviates things somewhat though the downside is that if you are mid edit when it happens you will lose your current edit.
My thinking is that I could overcome this if I could find a way to monitor for the 'F2' key (pressed after each edit), then only issue the save edits command after this is detected. I understand that this may not be possible with vbscript. I was hoping there was an 'opposite' to SendKeys though have been unable to find anything along those lines. Any suggestions?
Dim objShell
Set objShell = WScript.CreateObject( "WScript.Shell" )
objShell.Run("""C:\Program Files (x86)\ArcGIS\Desktop10.2\bin\ArcMap.exe""")
Do While True
Wscript.Sleep 300000
objShell.SendKeys "^%+S"
Loop

Operate a Desktop program with sofware

I would like to operate a (Windows) Desktop program. Because i use this on a daily basis to do some simple operaition. (Open a file PDF file, render it and save it in another folder).
I would like to do this by using somekind of service or script. I have been looking into VBscript to do this but i'm getting stuck at some operations that are normally done by users.
For example if i would like to open a file a user would go to File > Open and select the desired file. Off course the script could go to file and open but how do you select a certain file (the newest file in a certain folder).
Is it possible to have a piece of code to do these operations within a Desktop program or am i trying to do something impossible or maybe i'm using the wrong tools. Below a piece off testcode for what i'm trying to accomplish.
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run """C:\Program Files (x86)\programname.exe"""
wsh.sleep 1000 ' wait 1 second
WshShell.AppActivate """Program name"""
WshShell.SendKeys "^o" ' Open file
Any help is greatly appreaciated.
You are trying to control an application through its GUI, but it is not designed for that.
Having said that, I estimate this will be a nightmare if you do not use tools (or an app :-) ) explicitely created for that purpose, a la test robots like HP QTP or automation tools like Autoit http://www.autoitscript.com/site/autoit.
For example, if your application occasionally flushes the keyboard buffer, you might need to wait for some GUI event before sending the keystroke. This kind of synchronization is not accomplishable using vbscript only.

Resources