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"
Related
I wrote this little vbs script to press the left arrow key in my Chrome browser:
set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.AppActivate "Google Chrome"
WshShell.SendKeys "{LEFT}"
But it simulates a keypress with instant releases. Is there also a way to parse the pressed key over a longer time?
(I know that this would be easy to handle in Javascript by the Keypress even, but I am trying to learn vbs.)
The WshShell object does not provide a way to send KeyUp and KeyDown events. To closest you can get to what you want to do is by doing repetitions of the same key. This can be done by putting the .SendKeys in a loop or by putting a number after the key within the braces.
set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.AppActivate "Google Chrome"
WshShell.SendKeys "{LEFT 40}"
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
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?
I need to be able to make separte .vbs files that will (when triggered with a keyboard short-cut) will make the active window maximized, minimized, or restored.
How can I do this without downloading and installing (not allowed here) a separate package.
VBScript and Windows Script Host don't provide intrinsic functions for maximizing/minimizing/restoring a window. Without any third-party tools, your only option is to use SendKeys to simulate keyboard the shortcuts of the corresponding commands in a window's system menu.
To maximixe the active window, you can simulate the Alt+SpaceBar, x shortcut:
Set oShell = CreateObject("WScript.Shell")
oShell.SendKeys "% x"
To minimize the active window, use Alt+SpaceBar, n:
Set oShell = CreateObject("WScript.Shell")
oShell.SendKeys "% n"
To restore the active window, use Alt+SpaceBar, r:
Set oShell = CreateObject("WScript.Shell")
oShell.SendKeys "% r"
(Note that this code won't work in non-English Windows versions, where the names of the Maximize/Minimize/Restore commands are localized and therefore have other shortcuts.)
SendKeys was not working in my computer. Spanish native with Spanish and English keyboard. I did this and worked in my code as instruction and worked to maximize my excel window. I put the .Sleep to visually check it.
objExcel.SendKeys"% x"
objExcel.Visible = True
objExcel.SendKeys"% x"
WScript.Sleep 2000
To maximize any window, the following code will work:
Application.SendKeys "%{ }"
Application.Wait (Now + TimeValue("00:00:02"))
Application.SendKeys "x"
Topic is old. But I managed to find language independent solution. SendKeys can basically send any keys to application, including arrow keys and enter key. So we can emulate those actions without particular letters (x,r,n). Here is working example:
Dim oShell : Set oShell = CreateObject("WScript.Shell")
oShell.SendKeys("% {DOWN}{DOWN}{DOWN}{DOWN}{ENTER}") 'Maximize
'...
oShell.SendKeys("% {ENTER}") 'Restore
'...
oShell.SendKeys("% {DOWN}{DOWN}{DOWN}{ENTER}") 'Minimize
This works for me in my Excel macro to maximise an external PDF document by executing the shortcut keys 'Alt+Spacebar+x'.
Mote: '%' represents the Alt key, '( )' represents the spacebar key and 'x' represents the maximise key.
Application.SendKeys "%+( )+(x)", True
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