VB icon

Windows 10 VBScript SendKeys Demonstration

Email
Submitted on: 4/6/2018 7:17:15 PM
By: A_X_O 
Level: Beginner
User Rating: Unrated
Compatibility: VbScript (browser/client side)
Views: 1676
 
     A very simple sample of VBScript SendKeys on Windows 10.
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
'**************************************
' Name: Windows 10 VBScript SendKeys Demonstration
' Description:A very simple sample of VBScript SendKeys on Windows 10.
' By: A_X_O
'**************************************

'
'------------------------------------------------------------------------------	'
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++	'
'		Demonstration: Windows 10, VBScript; SendKeys			'
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++	'
'										'
'	Purpose		:	Demonstrates VBScript SendKeys Function		'
'	-----------------------------------------------------------------------	'
'	Creation Date	: 	17/03/2018 [dd/mm/yyyy]				'
'	Version		:	1.1						'
'	Designer	:	Fabian						'
'										'
'##############################################################################	'
'			MODIFICATION HISTORY					'
'------------------------------------------------------------------------------	'
'	Version		:	1:0	17/03/2018	Create the Sample	'
'	Version		:	1:1	31/03/2018	Close Notepad at End	'
'										'
'------------------------------------------------------------------------------	'		
'
Dim ObjShell									'	Create the memory dimensions for the scripting object 
Dim AppActivate									'	Create the memory dimensions for Notepad
'
Public Const ObjNotePad = "Notepad.exe"						'	Store notepade early on
Public Const IntDelay = 250							'	Define the WScript Sleep duration
'
'										'	Message String To Be Split And Displayed 
'
Public Const strMessage = "Welcome|to|Planet Source Code|Here|is|a|sample|of|VBScript SendKeys Function"
'
Public Const g_tCDelete	= "{DEL}"						'	SendKeys: DELETE 
Public Const g_tCSelect	= "^+{HOME}"						'	SendKeys: CONTROL and HOME
Public Const g_tConfirm	= "{ENTER}"						'	SendKeys: ENTER
Public Const g_tCStart	= "36"							'	SendKeys: Sample Font Size 36
Public Const g_tCStop	= "10"							'	SendKeys: Rest Font Size At End To 10
Public Const g_tBarMenu	= "%+o"							'	SendKeys: Format Font option on ToolBar Menu
Public Const g_tCFont	= "f"							'	SendKeys: Font 
Public Const g_tCName	= "Arial"						'	SendKeys: Font Name
Public Const g_tCNext	= "{TAB}"						'	SendKeys: Move System Focus To Next Font Dialog Option
Public Const g_tCStyle	= "Regular"						'	SendKeys: SendKeys: Style Of Font
Public Const g_tCEnd	= "%+{F4}"						'	SendKeys: Close Notepad after reseting the font.
'								 										
Set ObjShell = WScript.CreateObject("WScript.Shell")				'	Create the scripting object: The Environment to work in
'
AppActivate = ObjShell.Run(ObjNotePad, 1) 					'	Fire up Notepad and use as an Interface
'
Dim i										'	Memory Dimention i For a Loop
Dim iCounter									'	Memory Dimention iCounter For a Loop
Dim iPart									'	Memory Dimention iPart to Count Message Segments
Dim MyString									'	Memory Dimention MyString for each Message part in the String
'
Call ModifyFont(0)								'	Call ModifyFont with 0: First Run
'
Public Sub ModifyFont(ByVal intFontSize)					'	Setup the demonstration font 
On Error Resume Next
'
With WScript									'	Set the font
'
	.Sleep IntDelay * 4	: ObjShell.SendKeys g_tBarMenu
	.Sleep IntDelay		: ObjShell.SendKeys g_tCFont
	.Sleep IntDelay		: ObjShell.SendKeys g_tCName
	.Sleep IntDelay		: ObjShell.SendKeys g_tCNext
	.Sleep IntDelay		: ObjShell.SendKeys g_tCStyle
	.Sleep IntDelay		: ObjShell.SendKeys g_tCNext
'
If intFontSize = 0 Then								'	Check if this is the start of the demo or the end
'
	ObjShell.SendKeys g_tCStart						'	Start
'
Else										'	If not the Start, Must be the End
'
	ObjShell.SendKeys g_tCStop
										'	End of demo 
'
End If
'
	.Sleep IntDelay		: ObjShell.SendKeys g_tConfirm			'	Set font for either start or end
	.Sleep IntDelay * 2
										'	Determine script process position, ie: start or end. If at end, then clean-up
If iPart <> VbNullString And intFontSize = 1 Then
'
	ObjShell.SendKeys g_tCEnd	
'
End If
'
End With
'
End Sub
'
For iCounter = 1 To Len(strMessage) 						'	Move through the message string and count parts
'
If Mid((strMessage), iCounter, 1 ) = "|" Then
'
	iPart = iPart + 1							'	iPart is the Dimension that holds the integer (Dim iPart As Integer)
'
End If
'
Next
'
For i = 0 To iPart								'	Put each message part in the MyString Array
'
	MyString = Split(strMessage, "|", -1, 1)
'
	ObjShell.SendKeys MyString(i)						'	Send each message part in turn to notepad
'
With WScript
'
	.Sleep IntDelay * 6	: ObjShell.SendKeys g_tCSelect			'	Pause a little, select the text
	.Sleep IntDelay * 2	: ObjShell.SendKeys g_tCDelete			'	Delete the selected text
'
End With
'
Next
'
	WScript.Sleep IntDelay * 2						'	At the end of the message pause a little
'
Call ModifyFont(1)	


Other 7 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.