Tiling specifically named windows/applications - vbscript

I am attempting to tile two windows horizontally, i.e. the equivalent of selecting two programs from the Task Manager and selecting tile horizontally.
At present I can achieve this with VBScript only by minimising all windows and then restoring the two that I would like to be tiled, as per the below code.
Is there anyway to tile two applications of specific name using VBScript (or otherwise) without minimising everything and without having to load the application through VBScript?
Dim objShell
Set objShell = CreateObject("Shell.Application")
objShell.MinimizeALL
WScript.Sleep 500
Set shl = CreateObject("WScript.Shell")
shl.AppActivate "Application 1"
WScript.Sleep 500
shl.SendKeys "% r"
WScript.Sleep 500
shl.AppActivate "Application 2"
shl.SendKeys "% r"
WScript.Sleep 500
objShell.TileVertically
Set shl = Nothing
Set objShell = Nothing

Related

Script opens infinite instances of Internet Explorer, without setting active window

I wrote a vbscript program to automatically join Google Meet sessions, with the code that is required to enter the meet generated based on the date and time. Whenever I run the program, it opens in the background of the computer in infinite windows(repeatedly opening a new instance of Google Meet every second). The keystrokes that are supposed to be directed toward Internet Explorer are instead sent to whatever is active. The line of code that is supposed to make it the active window are not working: WshShell.AppActivate "Internet Explorer" I believe that this below section is what is causing problems. Any help is greatly appreciated!
option explicit
dim webbrowser, WshShell
set webbrowser = createobject("internetexplorer.application")
set WshShell = createobject("Wscript.Shell")
webbrowser.statusbar = false
webbrowser.menubar = false
webbrowser.toolbar = false
webbrowser.visible = true
webbrowser.navigate("https://meet.google.com/")
wscript.sleep(3000)
WshShell.AppActivate Internet Explorer
WshShell.sendkeys "{enter}"
I don't know why did you use sendkeys ?
You should write something like that :
Option explicit
dim webbrowser
set webbrowser = createobject("internetexplorer.application")
webbrowser.statusbar = false
webbrowser.menubar = false
webbrowser.toolbar = false
webbrowser.visible = true
webbrowser.navigate("https://meet.google.com/")
Do while webbrowser.readystate <> 4
wscript.sleep 200
Loop

CTRL+1 is not working

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

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"

Resources