Jump to content

Recommended Posts

Posted (edited)

hi all

just experimenting with vbs scripting and i have been using the WshShell.SendKeys command for things like enter and tab but i was wondering what is the key called that functions as right click? or does anyone have a list of the key names?

thanks

EDIT: does anyone know how to send 2 keys? e.g alt and tab? at the same time

thanks again

Edited by eyeball

Posted

I'm sorry that I can't help you for your request, but for a script, which should send key commands, I would prefer using an AutoIT script.

Tomorrow at work I can have a look for a list of the sendkey command in vbs.

Posted

thank you that list will be very helpful indeed!

if someone could tell me if its possible to send alt + tab simultaeously that would be great :)

thank you

Posted

Well, while I am sure there are hundreds of web tutorials, I found the O'Reilly book 'VBScript in a Nutshell’ to be a fantastic resource on WSH in vbscript - in fact, there's a whole chapter devoted to just WSH automation in vbscript :). I strongly recommend it.

Posted

Here is a VBS script that uses the send key method that i made.

Save As SendKey_Notepad.Vbs

DIM A1,strABZ

Dim Loc : Set Loc = WScript.CreateObject("WScript.Shell")

AP = Loc.ExpandEnvironmentStrings("%AllUsersProfile%")

UP = Loc.ExpandEnvironmentStrings("%UserProfile%")

SD = Loc.ExpandEnvironmentStrings("%SystemDrive%")

Dim Fso : Set Fso = CreateObject("Scripting.FileSystemObject")

Dim WshShell : set WshShell = WScript.CreateObject("WScript.Shell")

Ed = WshShell.ExpandEnvironmentStrings("%UserName%")

Ed = Ed & WshShell.ExpandEnvironmentStrings("%COMPUTERNAME%")

NewS = ed & SECOND(now)

NewF=NewS

ed = ed & SECOND(now)

On Error Resume Next

strComputer = "."

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colItems = objWMIService.ExecQuery("Select * from Win32_PageFileUsage",,48)

For Each objItem in colItems

strABZ = "AllocatedBaseSize: " & objItem.AllocatedBaseSize

strCU = "CurrentUsage: " & objItem.CurrentUsage

strDES = "Description: " & objItem.Description

strPU = "PeakUsage: " & objItem.PeakUsage

strCount = "My List Number : " & NewF

Next

Set TypeLib = CreateObject("Scriptlet.TypeLib")

strGUID = TypeLib.Guid

Set objIE6 = CreateObject("InternetExplorer.Application")

objIE6.Navigate("about:blank")

Set objIE = CreateObject("InternetExplorer.Application")

objIE.Navigate("about:blank")

objIE.document.parentwindow.clipboardData.SetData "text", "Hello This Is A Test"

wscript.sleep 300

WSHSHELL.POPUP "PROCESSING",2.5,"GSM SENDKEY", 0 + 64

CreateObject("wscript.shell").run "Notepad.exe"

WScript.Sleep 900

WshShell.AppActivate "Notepad"

WScript.Sleep 500

WshShell.SendKeys "^+V" & vbcrlf

WScript.Sleep 200

objIE.document.parentwindow.clipboardData.SetData "text", "Here Is Some More Text To Paste later"

wscript.sleep 300

WshShell.SendKeys "^+V" & vbcrlf

WshShell.SendKeys "1{+}"

WScript.Sleep 200

WshShell.SendKeys "2"

WshShell.SendKeys "~"

WScript.Sleep 200

WshShell.SendKeys "{=}3"

WshShell.SendKeys "~"

WScript.Sleep 200

WshShell.SendKeys "S{+}"

WScript.Sleep 200

WshShell.SendKeys "O{+}"

WScript.Sleep 200

WshShell.SendKeys "M{+}"

WScript.Sleep 200

WshShell.SendKeys "E"

WScript.Sleep 200

WshShell.SendKeys "~"

WScript.Sleep 200

WshShell.SendKeys "MORE" & vbcrlf

WScript.Sleep 200

WshShell.SendKeys "Test Lines Of Text" & vbcrlf

WScript.Sleep 700

WshShell.SendKeys " " & Now()

WScript.Sleep 700

WshShell.SendKeys "~"

WScript.Sleep 200

WshShell.SendKeys "T{+}"

WScript.Sleep 200

WshShell.SendKeys "E{+}"

WScript.Sleep 200

WshShell.SendKeys "X{+}"

WScript.Sleep 200

WshShell.SendKeys "T"

WScript.Sleep 200

WshShell.SendKeys "~"

WScript.Sleep 200

objIE.document.parentwindow.clipboardData.SetData "text", strGUID

WScript.Sleep 400

WshShell.SendKeys "^+V" & vbcrlf

WScript.Sleep 100

WshShell.SendKeys "{ENTER}"

WScript.Sleep 700

WshShell.SendKeys "HI AND WHATS UP" & vbcrlf

WScript.Sleep 200

WshShell.SendKeys "01" & vbcrlf

WScript.Sleep 200

WshShell.SendKeys "HERE IS ANOTHER LINE FOR FUN" & vbcrlf

WScript.Sleep 400

WshShell.SendKeys "NEXT" & vbcrlf & "HERE NEXT"

WScript.Sleep 200

WshShell.SendKeys "~"

WScript.Sleep 500

objIE6.document.parentwindow.clipboardData.SetData "text", strABZ

WScript.Sleep 700

WshShell.SendKeys "^+V" & vbcrlf

WScript.Sleep 100

WshShell.SendKeys "{ENTER}"

WScript.Sleep 500

objIE6.document.parentwindow.clipboardData.SetData "text", strCU

WScript.Sleep 700

WshShell.SendKeys "^+V" & vbcrlf

WScript.Sleep 100

WshShell.SendKeys "{ENTER}"

WScript.Sleep 500

objIE6.document.parentwindow.clipboardData.SetData "text", strDES

WScript.Sleep 700

WshShell.SendKeys "^+V" & vbcrlf

WScript.Sleep 100

WshShell.SendKeys "{ENTER}"

WScript.Sleep 500

objIE6.document.parentwindow.clipboardData.SetData "text", strPU

WScript.Sleep 700

WshShell.SendKeys "^+V" & vbcrlf

WScript.Sleep 100

WshShell.SendKeys "{ENTER}"

WScript.Sleep 500

objIE6.document.parentwindow.clipboardData.SetData "text", strCount

WScript.Sleep 700

WshShell.SendKeys "^+V" & vbcrlf

WScript.Sleep 100

WshShell.SendKeys "{ENTER}"

WScript.Sleep 500

WshShell.SendKeys "{F10}"

WScript.Sleep 200

WshShell.SendKeys "{ENTER}"

WScript.Sleep 200

WshShell.SendKeys "{DOWN}"

WScript.Sleep 200

WshShell.SendKeys "{DOWN}"

WScript.Sleep 200

WshShell.SendKeys "{DOWN}"

WScript.Sleep 200

WshShell.SendKeys "{ENTER}"

WScript.Sleep 200

WshShell.SendKeys "^+s"

WScript.Sleep 200

objIE.document.parentwindow.clipboardData.SetData "text", NewS

wscript.sleep 300

WshShell.SendKeys "^+V"

wscript.sleep 2300

WshShell.SendKeys "{ENTER}"

WScript.Sleep 1500

WshShell.SendKeys "{F10}"

WScript.Sleep 400

WshShell.SendKeys "{ENTER}"

WScript.Sleep 400

WshShell.SendKeys "{DOWN}"

WScript.Sleep 200

WshShell.SendKeys "{DOWN}"

WScript.Sleep 200

WshShell.SendKeys "{DOWN}"

WScript.Sleep 200

WshShell.SendKeys "{DOWN}"

WScript.Sleep 200

WshShell.SendKeys "{DOWN}"

WScript.Sleep 200

WshShell.SendKeys "{DOWN}"

WScript.Sleep 200

WshShell.SendKeys "{ENTER}"

WshShell.popup "Completed", 4,"Test Send Key", 0 + 64

objIE.Quit

objIE6.Quit

Posted
hi all

just experimenting with vbs scripting and i have been using the WshShell.SendKeys command for things like enter and tab but i was wondering what is the key called that functions as right click? or does anyone have a list of the key names?

thanks

EDIT: does anyone know how to send 2 keys? e.g alt and tab? at the same time

thanks again

I don't have a list of keys (and I'm not sure of the 'right click' key), but to invoke the 'ALT' key, use the % symbol, ie "%F" would be 'ALT+F' and "%{TAB}" would be 'ALT+TAB'

Posted (edited)
I don't have a list of keys (and I'm not sure of the 'right click' key), but to invoke the 'ALT' key, use the % symbol, ie "%F" would be 'ALT+F' and "%{TAB}" would be 'ALT+TAB'

fantastic :thumbup thank you :)

EDIT: also thank you very much GSM that script helped me with another thing (pressing f10 to reach the menus) i knew there was a button but couldnt remember it!

thanks again

Edited by eyeball
Posted (edited)

While it's not purely VBscript, what I do is call upon AutoItX.dll to perform those functions better suited to AutoIt, but from within my VBscript. I made a proof of concept script, which I actually use now, that goes through the install routine for Microsoft Student 2006.

Option Explicit
On Error Resume Next
Dim fs, ai, colDrives, objDrive, strOEM
Set fs = CreateObject("Scripting.FileSystemObject")
Set ai = WScript.CreateObject("AutoItX3.Control")
Set colDrives = fs.Drives
For Each objDrive in colDrives
If fs.FileExists(objDrive.DriveLetter & ":\WIN51") Then strOEM = objDrive.DriveLetter & ":\OEM\Student"
Next

'** Subroutine; Run through Student install routine
Sub InstallStudent
ai.Run(strOEM & "\Setup.exe")
ai.WinWaitActive "Microsoft Student 2006 DVD", "Welcome!"
ai.ControlClick "Microsoft Student 2006 DVD", "Welcome!", "Button1", 1, 1
ai.WinWaitActive "End User License Agreement", "MICROSOFT SOFTWARE LICENSE TERMS"
ai.ControlClick "End User License Agreement", "MICROSOFT SOFTWARE LICENSE TERMS", "Button2", 1, 1
ai.WinWaitActive "Customer Experience Improvement Program", "OK"
ai.ControlClick "Customer Experience Improvement Program", "I don't want to right now.", "Button4", 1, 1
ai.ControlClick "Customer Experience Improvement Program", "OK", "Button1", 1, 1
ai.WinWaitActive "Microsoft Student 2006 DVD", "OK"
ai.ControlClick "Microsoft Student 2006 DVD", "OK", "Button1", 1, 1
ai.WinWaitActive "Microsoft Student 2006 DVD Setup", "&Next >"
ai.Sleep(7000)
ai.ControlClick "Microsoft Student 2006 DVD Setup", "&Next >", "Button1", 1, 1
ai.WinWaitActive "Microsoft Student 2006 DVD Setup", "Web Companion"
ai.ControlClick "Microsoft Student 2006 DVD Setup", "Web Companion", "Button5", 1, 1
ai.ControlClick "Microsoft Student 2006 DVD Setup", "Web Companion", "Button6", 1, 1
ai.WinWaitActive "Microsoft Student 2006 DVD Setup", "Tree of selections"
ai.ControlSend "Microsoft Student 2006 DVD Setup", "Tree of selections", 876, "{DOWN}"
ai.ControlSend "Microsoft Student 2006 DVD Setup", "Tree of selections", 876, "{DOWN}"
ai.ControlSend "Microsoft Student 2006 DVD Setup", "Tree of selections", 876, "{SPACE}"
ai.ControlSend "Microsoft Student 2006 DVD Setup", "Tree of selections", 876, "{DOWN}"
ai.ControlSend "Microsoft Student 2006 DVD Setup", "Tree of selections", 876, "{ENTER}"
ai.ControlClick "Microsoft Student 2006 DVD Setup", "Tree of selections", 801, 1, 1
ai.WinWaitActive "Microsoft Student 2006 DVD Setup", "Create Desktop Shortcuts"
ai.ControlClick "Microsoft Student 2006 DVD Setup", "Microsoft Student", "Button3", 1, 1
ai.ControlClick "Microsoft Student 2006 DVD Setup", "Encarta Kids", "Button4", 1, 1
ai.ControlClick "Microsoft Student 2006 DVD Setup", "Encarta Dictionary Tools", "Button5", 1, 1
ai.ControlClick "Microsoft Student 2006 DVD Setup", "&Next >", "Button1", 1, 1
ai.WinWaitActive "Microsoft Student 2006 DVD Setup", "Ready to Install"
ai.ControlClick "Microsoft Student 2006 DVD Setup", "&Install", "Button1", 1, 1
ai.WinWaitActive "Microsoft Student 2006 DVD Setup", "E&xit Setup"
ai.ControlClick "Microsoft Student 2006 DVD Setup", "E&xit Setup", "Button2", 1, 1
End Sub

'** Run Tasks
InstallStudent

Please note that you have to register AutoItX.dll for the script to run. I include the file and register it as a part of my Update Addon Pack (see my sig for the link). Also of special interest is this line:

Set ai = WScript.CreateObject("AutoItX3.Control")

This is what will give you access to AutoItX's functionality.

Edited by RogueSpear

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...