CTRL+1 is not working - vbscript

Option Explicit
Dim WshShell
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run """C:\Program Files (x86)\Blackmagic Design\Blackmagic Media Express\MediaExpress.exe""" ,1,true
Wscript.Sleep 100
WshShell.SendKeys "^1"
Set WshShell = Nothing

.SendKeys method uses alphanumeric keypad for transmitting digits. My keyboard (the line with numbers under the uppermost EscF1… key row) behaves as follows (using Czech keyboard input):
°1234567890 with Shift
;+ĚŠČŘŽÝÁÍÉ with CapsLock
;+ěščřžýáíé unmodified
I can confirm that e.g. WshShell.SendKeys "^1" (with Windows Script Host Version 5.8) sends Ctrl+Shift+1 keystrokes to the active window as if typed on the keyboard.
My answer: I need to use WshShell.SendKeys "^{+}" to emulate keyboard Ctrl+1 input.
Above .SendKeys behaviour is independent on current keyboard layout (input method) in calling cmd window (cscript //nologo 34189495.vbs) and in window activated right before WshShell.SendKeys "^1". Tested all combinations of
- Windows display language English (UK), keyboard input method Czech/United Kingdom and
- display language Czech, keyboard input method Czech/US-international,
each versus each other…
Another problem: how to emulate keyboard input Ctrl+2 using .SendKeys method? I can't use simply WshShell.SendKeys "^{ě}". It does not work because ě (latin small letter E with caron) hexadecimal value is greater than 0x79 (and ščřžýáíé as well). As per Keyboard Scan Code Specification Microsoft document, Prefixed Scan Codes part (sorry for link to download):
If you use scan codes from the 0xE0 set, make sure the second byte
is suitable in the same way as single byte scan code values. In other
words: Not greater than 0x79, Not 0x60 or 0x61, Not 0x00…
However, here is a workaround: WshShell.SendKeys "{NUMLOCK}^{ě}{NUMLOCK}" (who knows why it works? Derived from my previous experience with keyboard wedge barcode scanners!)
Addendum: tested using my preferred text and code editor PSPad;
Here is my working code:
option explicit
'On Error Resume Next
On Error GoTo 0
Dim WshShell
set WshShell = WScript.CreateObject("WScript.Shell")
' WshShell.Run omitted, activate existing window (this script open in PSPad)
WScript.Sleep 100
WshShell.AppActivate "34189495.vbs"
WScript.Sleep 200
' Ctrl+Shift+3 set marker #3
WshShell.SendKeys "^3"
WScript.Sleep 100
' Ctrl+1 goto marker #1, i.e. move cursor to that line (pre)marked 1
WshShell.SendKeys "^{+}"
' more time to observe
WScript.Sleep 3000
' Ctrl+3 goto marker #3, i.e. move cursor to that line marked 3
WshShell.SendKeys "{NUMLOCK}^{Š}{NUMLOCK}"
WScript.Sleep 100
' more time before quit
WScript.Sleep 3000
Wscript.Echo Wscript.ScriptName
Wscript.Quit

Related

VBScript "ALTt" or "{ENTER}" don't select the button, it merely highlights it

There is a "Test" button, in an application that I'm looking to automatically select.
I'm using VBScript and have tried "ALTt" (t is the underlined character in the button's text) and "{ENTER}" but it merely highlights the button and doesn't actually select it.
Here's the script:
Set WshShell = WScript.CreateObject("WScript.Shell")
Set oShell = CreateObject("WScript.Shell")
WshShell.AppActivate "IMPORT"
WshShell.SendKeys "ALTt"
or
Set WshShell = WScript.CreateObject("WScript.Shell")
Set oShell = CreateObject("WScript.Shell")
WshShell.AppActivate "IMPORT"
WshShell.SendKeys "{TAB}"
WshShell.SendKeys "{TAB}"
WshShell.SendKeys "{ENTER}"
Unfortunately, as mentioned this just highlights the button.
I've also tried the tilde character in place of "{ENTER}" but it yields the same results.
I think Space can also "press" a button once it has focus, you can give that a shot.
As far as sending ALT, take a look at the Microsoft documentation for SendKeys statement, you should be sending %t according to that.

vbscript - how to send keystrokes to internet explorer

I've read every question that came up when I typed my title, as well as several other web pages, and I still haven't found the answer I'm looking for. I believe this is fairly straightforward, just must be missing something as my program doesn't do anything.
Here's what I want it to do (for all practical purposes, let's say I'm searching for my favorite discussion here on SO):
Have the main SO page loaded (stackoverflow.com/).
Utilize the Open File (CTRL+O) feature of IE to enter the specific address of the page I'm looking for.
Utilize the Select All (CTRL+A) feature to highlight the entire text to be copied.
Utilize CTRL+C and CTRL+V to, respectively, copy and paste this into a word document for presentation purposes.
Here's the code I have so far:
' Sets up the objects.
Dim objIE, WshShell, objWord
Set wshShell = WScript.CreateObject ("WSCript.shell")
Set objIE = CreateObject("InternetExplorer.Application")
Set objWord = Application.CreateObject("Word.Application")
Dim i, strUserID
with CreateObject("InternetExplorer.Application")
wshShell.SendKeys "^O"
.navigate "http://stackoverflow.com/questions/[link of question would go here]"
wshShell.SendKeys "^A"
wshShell.SendKeys "^C"
AppActivate ("Document1 - Microsoft Word")
wshShell.SendKeys "^V"
end with
For some reason, this isn't working the way I want it to. Any suggestions?

App ignores VBS SendKeys

Trying to automate report generation by sending keystrokes to an application.
I can bring the app forward but then it ignores all SendKeys commands.
What is the problem? What should I try next?
this is my code:
Const App_Title = "AccountRight Plus" ' Window title
Dim Wsh, win_title
' Create the WshShell object, which Run and AppActivate require.
Set Wsh = WScript.CreateObject("WScript.Shell")
Wsh.AppActivate App_Title
WScript.Sleep 800
Wsh.SendKeys "^i"
WScript.Sleep 800
Wsh.SendKeys "{TAB}"
WScript.Sleep 800
Wsh.SendKeys "{TAB}"
Probably you have confusion with the caps lock key and stroke "^i". Just hypothesis anyway. If this is not the case then at least not judge me.
So I made a code that I can test here, to explain what I mean.
Set Wsh = WScript.CreateObject("WScript.Shell")
Wsh.Run "notepad"
Wsh.AppActivate "Untitled - Notepad"
WScript.Sleep 100
Wsh.SendKeys "111..."
WScript.Sleep 100
Wsh.SendKeys "^a" ' (ctrl+a) Select All command
If by chance the caps lock key is off, above code will select all text, but stroke "^a" (or even "^(a)") will fail if caps lock is on. And contrariwise, if you use "^A" will fail with caps lock off.
There no way to get the state of caps lock (or other keys) in VBScript, but I found 2 work arounds, call them cheats if you like :)
A bit weird way to go, is to duplicate your SendKeys command.
Wsh.SendKeys "^a" : Wsh.SendKeys "^a"
To send stroke to caps lock in advance.
Wsh.SendKeys "{CAPSLOCK}" : Wsh.SendKeys "^a"

VBScript SendKeys CTRL+LWIN+TAB?

I am trying to write a simple script that will send the key combo of CTRL+WINDOWS KEY+TAB. The code below sends the keys CTRL+ALT+TAB
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.SendKeys "^%{TAB}"
However when I try to replace "%" (aka the ALT key) with LWIN (aka the Left Windows Key) it says Syntax Error.
I tried the following, but had no luck:
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.SendKeys "^{LWIN}{TAB}"
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.SendKeys "^{LWIN}+{TAB}"
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.SendKeys ^{LWIN}+{TAB}
I know it has something to do with being able to Hold certain keys while other keys are pressed but I can't seem to get it right.
The windows key can be pressed programmatically using CTRL+ESC. Is there a way to set this combination as a variable called LWIN and then use one of the above Scripts?
Just in case someone land here on these years...
A workaround (instead of sending keystrokes) is to call directly to the application:
Set objShell = CreateObject("Shell.Application")
objShell.WindowSwitcher
This will open Task Switcher Windows App. (Same as ⊞ windows+TAB)
try this code:
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.SendKeys "+(^{LWIN}{TAB})"
I know you are looking for VBscript but it looks like that is unlikely (pure VBscript). Here is a post that did solve this via C#.
https://stackoverflow.com/a/10367832/1742115
This page tells how to call the C# DLL from your VBscript if you want to keep some of this in vbs.
I think your question is an example of an XY problem and what you actually want to do is to activate Flip 3D (Switch between windows). You can do this programmatically by executing the rundll32 DwmApi #105 command:
CreateObject("WScript.Shell").Run "rundll32 DwmApi #105"

Focus moves next tab if user press any key

I tried making a script that should perform the following functions:
runs in background
focus moves to next tab if user press any key
run on windows platform.
I used the following code but its not working :(
Please correct me if I had made a error in code.
Set wshShell = WScript.CreateObject("WScript.Shell")
Dim a
Do
a = WScript.StdIn.Read(1)
wshShell.SendKeys "{TAB}"
Loop

Resources