Search Tools Links Login

Solution for Windows Vista


Use of the API SendInput instead of SendKeys!
This will prevent the error of access denied in the Windows Vista.

Original Author: Rodrigo da Silva Brito

Code


Use of the API SendInput instead
of SendKeys

This will prevent the error of access denied in the Windows Vista.


 


They forgive me but my English is
not very good! I am Brazilian!



Copy and paste this code in a module of vb! It will go to substitute the
SendKeys standard of the VB!

 


Option
Explicit




Private Const KEYEVENTF_KEYUP = &H2

Private Const INPUT_KEYBOARD = 1



Private Type KEYBDINPUT

wVk As Integer

wScan As Integer

dwFlags As Long

time As Long

dwExtraInfo As Long

End Type



Private Type GENERALINPUT

dwType As Long

xi(0 To 23) As Byte

End Type



Private Declare Function SendInput
Lib "user32.dll" (ByVal
nInputs As Long, pInputs
As GENERALINPUT, ByVal
cbSize As Long) As Long

Private Declare Sub CopyMemory
Lib "kernel32" Alias "RtlMoveMemory"
(pDst As Any, pSrc As Any,
ByVal ByteLen As Long)



Public Function SendKeysA(ByVal
vKey As Integer,
Optional
booDown As Boolean =
False)

Dim GInput(0) As GENERALINPUT

Dim KInput As KEYBDINPUT

KInput.wVk = vKey

If Not booDown Then

    KInput.dwFlags = KEYEVENTF_KEYUP

End If

GInput(0).dwType = INPUT_KEYBOARD

CopyMemory GInput(0).xi(0), KInput, Len(KInput)

Call SendInput(1, GInput(0), Len(GInput(0)))

End Function



Using in form!

Example: Instead of SendKeys (ǣ{TAB}) you it will use SendKeys vbKeyTab, True

 


Simulation:

Before!


Private Sub Form_KeyPress(KeyAscii
As Integer)

If KeyAscii = vbKeyReturn
Then


   SendKeys ("{TAB}")

   KeyAscii = 0

End If

End Sub




Later!

Private Sub Form_KeyPress(KeyAscii
As Integer)

If KeyAscii = vbKeyReturn
Then


   SendKeys vbKeyTab, True

   KeyAscii = 0

End If

End Sub


 


Abra?os.

Solu??o para o Windows Vista! Envio de teclas atrav?s da API SendInput!

About this post

Posted: 2002-06-01
By: ArchiveBot
Viewed: 104 times

Categories

Visual Basic 6

Attachments

No attachments for this post


Loading Comments ...

Comments

No comments have been added for this post.

You must be logged in to make a comment.