Find Code:
All Words
Any of the Words
Exact Phrase
Home
:
Code
:
Forums
:
Submit
:
Mailing List
:
About
:
Contact
Code
All
VB.NET
ASP.NET
C#
VB Classic
ASP Classic
Snippets
Popular
Resources
Submit Code
Forums
Articles
Tips
Links
Books
Contest
Link to us
Send Keys Using Keybd_event as String
Author:
Bob Brandt
E-mail:
Click to e-mail author
Submitted:
4/28/2011
Version:
Compatibility:
VB6
Category:
Miscellaneous
Views:
15483
Send keybd_Events as string with all keyboard characters included. Upper Lower Case and Special ?}():>< characters.
Declarations:
'Place in Module Option Explicit Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long) Declare Function VkKeyScanEx Lib "user32" Alias "VkKeyScanExA" (ByVal ch As Byte, ByVal dwhkl As Long) As Integer Const KEYEVENTF_EXTENDEDKEY = &H1 Const KEYEVENTF_KEYDOWN = &H0 Const KEYEVENTF_KEYUP = &H2 Const VK_Shift = &HA0
Code:
'Place in Form Private Sub Command1_Click() Dim MyWordsToSend As String Dim FormName As String FormName = "Form1" MyWordsToSend = "abcdefQRSTUV?>}{)(*&^%$#@.,/\" 'String to Send Call SendStrings(MyWordsToSend, FormName) End Sub 'Place below in Module Public Sub SendStrings(MyWordsToSend As String, FormName As String) Dim I As Integer Dim CurrentLetter As String Dim UpperLowerCaseCheck As String Dim UpperCase As Boolean Dim CurrentFormName As Form 'Bob Brandt, Hartsburg Missouri Select Case FormName Case Is = "Form1" Set CurrentFormName = Form1 'Form that sent WordsToSend, ie: "Form1" 'Case Is = "FormAnyName" 'Set CurrentFormName = AnyformName End Select CurrentFormName.WindowState = 1 For I = 1 To Len(MyWordsToSend) CurrentLetter = (Mid(MyWordsToSend, I, 1)) 'Separates out each letter to send UpperLowerCaseCheck = LCase(Mid(MyWordsToSend, I, 1)) 'Part of U/Lower Case Check UpperCase = False If CurrentLetter <> UpperLowerCaseCheck Then 'Compares Letter for Upper or Lower Case keybd_event VK_Shift, 0, KEYEVENTF_KEYDOWN, 0 'If Letter is UpperCase, turns shift key On. UpperCase = True End If CurrentLetter = LCase(CurrentLetter) On Error Resume Next Call keybd_event(VkKeyScanEx(Asc(CurrentLetter), 1), KEYEVENTF_EXTENDEDKEY, 1, 1) 'Sends all letter in LowerCase If UpperCase = True Then keybd_event VK_Shift, 0, KEYEVENTF_KEYUP, 0 End If 'If Character is not on the Keybd_Event list, it Creates an ERROR If Err.Number <> 0 Then Select Case CurrentLetter Case Is = "?" CurrentLetter = "/" Case Is = ">" CurrentLetter = "." Case Is = "<" CurrentLetter = "," Case Is = "(" CurrentLetter = "9" Case Is = ")" CurrentLetter = "0" Case Is = "*" CurrentLetter = "8" Case Is = "!" CurrentLetter = "1" Case Is = "@" CurrentLetter = "2" Case Is = "#" CurrentLetter = "3" Case Is = "$" CurrentLetter = "4" Case Is = "%" CurrentLetter = "5" Case Is = "^" CurrentLetter = "^" Case Is = "&" CurrentLetter = "7" Case Is = "_" CurrentLetter = "-" Case Is = "+" CurrentLetter = "=" Case Is = "~" CurrentLetter = "`" Case Is = "{" CurrentLetter = "[" Case Is = "}" CurrentLetter = "]" Case Is = "|" CurrentLetter = "\" Case Is = ":" CurrentLetter = ";" Case Is = """" CurrentLetter = "'" End Select keybd_event VK_Shift, 0, KEYEVENTF_KEYDOWN, 0 Call keybd_event(VkKeyScanEx(Asc(CurrentLetter), 1), KEYEVENTF_EXTENDEDKEY, 1, 1) 'Send Special characters with shift key on keybd_event VK_Shift, 0, KEYEVENTF_KEYUP, 0 Err.Clear End If Next I CurrentFormName.WindowState = 0 End Sub
Home
|
Forums
|
Submit
|
Books
|
Mailing List
|
Advertising
|
About
|
Contact
© 2024 A1VBCode. All rights reserved.
Legal disclaimer & terms of use
Privacy statement