VBScript SendKeys CTRL+LWIN+TAB?
Asked Answered
C

4

6

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?

Cabal answered 13/10, 2012 at 22:20 Comment(4)
It is a dinosaur-and-humans time anachronism. VBScript was invented long before keyboards got a Windows key. Or perhaps more appropriately, they stopped maintaining VBScript a long, long time ago. Back in the previous century. Not supported in .NET's SendKeys either, look at something like AutoHotkey.Wohlen
I don't see how this could be true if there are people out there with guides on how to do key combinations such as WINDOWS KEY + X or WINDOWS KEY + M.Cabal
The windows key is simulated with CTRL+ESC (Refer to update above)Cabal
Ctrl+Esc doesn't simulate the Win key; it just calls the Start menu.Hyperacidity
L
5

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)

Loaning answered 8/12, 2016 at 19:23 Comment(0)
O
4

try this code:

Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.SendKeys "+(^{LWIN}{TAB})"
Operation answered 23/3, 2016 at 16:20 Comment(1)
doesn't work in win11Tuinenga
T
1

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://mcmap.net/q/368871/-sending-windows-key-using-sendkeys

This page tells how to call the C# DLL from your VBscript if you want to keep some of this in vbs.

Tuber answered 14/10, 2012 at 2:36 Comment(2)
Ok that could work but is it possible to run the proposed code without a gui? therefore acting like vbscript (Pure action and no visual evidence). my intention is to create a small script that will simulate the windows 3D Task Switcher. (Represented by CTRL+WIN+TAB)Cabal
This page, which contains the code, says it can be run as a console application... so no UI.Tuber
H
1

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"
Hyperacidity answered 16/7, 2013 at 8:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.