Aller s'il vous plait !
J'ai juste besoin qu'on m'aide à changer sa :
' Declarations and such needed for the example:
' (Copy them to the (declarations) section of a module.)
Public Type KEYBDINPUT
wVk As Integer
wScan As Integer
dwFlags As Long
time As Long
dwExtraInfo As Long
End Type
Public Const VK_P = &H50 ' using vbKeyP instead would also work
Public Const KEYEVENTF_KEYUP = &H2
Public Type INPUT_TYPE
dwType As Long
xi(0 To 23) As Byte
End Type
Public Const INPUT_KEYBOARD = 1
Public Declare Function SendInput Lib "user32.dll" (ByVal nInputs As Long, pInputs As INPUT_TYPE, _
ByVal cbSize As Long) As Long
Public Declare Sub CopyMemory Lib "kernel32.dll" Alias "RtlMoveMemory" (Destination As Any, Source _
As Any, ByVal Length As Long)
' *** Place the following code inside the form window. ***
Private Sub Command1_Click()
Dim inputevents(0 To 3) As INPUT_TYPE ' holds information about each event
Dim keyevent As KEYBDINPUT ' temporarily hold keyboard input info
' Load the information needed to imitate pressing the P key.
With keyevent
.wVk = VK_P ' the P key
.wScan = 0 ' not needed
.dwFlags = 0 ' press the key down
.time = 0 ' use the default
.dwExtraInfo = 0 ' not needed
End With
' Copy the structure into the input array's buffer.
inputevents(0).dwType = INPUT_KEYBOARD
CopyMemory inputevents(0).xi(0), keyevent, Len(keyevent)
' Do the same as above, but for releasing the P key.
With keyevent
.wVk = VK_P ' the P key
.wScan = 0 ' not needed
.dwFlags = KEYEVENTF_KEYUP ' release the key
.time = 0 ' use the default
.dwExtraInfo = 0 ' not needed
End With
inputevents(1).dwType = INPUT_KEYBOARD
CopyMemory inputevents(1).xi(0), keyevent, Len(keyevent)
' into the array, finally send it into the input stream.
SendInput 2, inputevents(0), Len(inputevents(0))
End Sub
Pour le rendre compatible vb.net !
J'ai bien fait :
Public Class Form1
Public Declare Function SendInput Lib "user32.dll" (ByVal nInputs As Long, ByVal pInputs As INPUT_TYPE, ByVal cbSize As Long) As Long
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Integer) As Short
Public Declare Sub CopyMemory Lib "kernel32.dll" Alias "RtlMoveMemory" (ByVal Destination As IntPtr, ByVal Source As IntPtr, ByVal Length As Long)
Public Structure KEYBDINPUT
Dim wVk As Integer
Dim wScan As Integer
Dim dwFlags As Long
Dim time As Long
Dim dwExtraInfo As Long
End Structure
Public Const VK_P = &H50 ' using vbKeyP instead would also work
Private Const VK_CTRL As Long = &HA2
Private Const VK_SPACE As Long = 32
Public Const KEYEVENTF_KEYUP = &H2
Public Structure INPUT_TYPE
Dim dwType As Long
Dim xi As Byte
End Structure
Public Const INPUT_KEYBOARD = 1
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
If GetAsyncKeyState(VK_CTRL) Then
Dim inputevents(0 To 4) As INPUT_TYPE ' holds information about each event
Dim keyevent As KEYBDINPUT ' temporarily hold keyboard input info
End If
With keyevent
.wVk = VK_SPACE ' the Space key
.wScan = 0 ' not needed
.dwFlags = 0 ' press the key down
.time = 0 ' use the default
.dwExtraInfo = 0 ' not needed
End With
' Copy the structure into the input array's buffer.
inputevents(0).dwType = INPUT_KEYBOARD
CopyMemory(inputevents(0).xi(0), keyevent, Len(keyevent))
' Do the same as above, but for releasing the P key.
With keyevent
.wVk = VK_SPACE ' the Space key
.wScan = 0 ' not needed
.dwFlags = KEYEVENTF_KEYUP ' release the key
.time = 0 ' use the default
.dwExtraInfo = 0 ' not needed
End With
inputevents(1).dwType = INPUT_KEYBOARD
CopyMemory(inputevents(1).xi(0), keyevent, Len(keyevent))
SendInput(2, inputevents(0), Len(inputevents(0)))
End Sub
Mais il me dit que inputevents et keyevent ne sont pas déclarés, hors :
Dim inputevents(0 To 4) As INPUT_TYPE ' holds information about each event
Dim keyevent As KEYBDINPUT ' temporarily hold keyboard input info
Et enfin j'ai retranscrit
xi(0 To 23) As Byte
En
Dim xi As Byte
mais j'ai un doute sur le si sa va changer quelque chose =)
Merci s'il vous plait de prendre 2 minutes pour ceux qui savent à m'aider :(