Monday, May 31, 2010

Keystroke automation through VBScript

I was looking for a solution, which should do collapse all for silktest code. It is needed before do code comparison. I tried simple VBScript and it is working fine. It is fully based on keystrokes. Below I've shared the code.

VBScript - Sending Keystrokes

' To Collapse All opened Silktest files ' Usage: wscript silktest_collapse.vbs 100 Dim WshShell, iItem, iCount If WScript.Arguments.Count > 0 Then iCount = CInt(WScript.Arguments.Item(0)) Else iCount = 10 End If Wscript.Echo "Count " & CStr(iCount) Set WshShell = Wscript.CreateObject("Wscript.Shell") 'WshShell.AppActivate "Silktest - *" WshShell.SendKeys "%{TAB}" Wscript.Sleep 5000 For iItem=1 to iCount 'To Collapse -> Alt+L+L WshShell.SendKeys "%" WshShell.SendKeys "l" Wscript.Sleep 200 WshShell.SendKeys "l" Wscript.Sleep 1000 'To Save -> Ctrl+S WshShell.SendKeys "^s" Wscript.Sleep 900 'To Close -> Alt+F+C WshShell.SendKeys "%" WshShell.SendKeys "f" Wscript.Sleep 200 WshShell.SendKeys "c" Wscript.Sleep 700 Next Wscript.Echo "Completed."

2 comments:

tehlexx said...

wouldn't it be easier to use Options -> General... -> Save Outline "Collapse All" ?

Palani Selvam said...

Great.. It is working fine.