Sendinput et vb.NET

cs_devoluti0n Messages postés 22 Date d'inscription lundi 14 mars 2005 Statut Membre Dernière intervention 14 juin 2008 - 7 avril 2007 à 17:34
werdDomain Messages postés 60 Date d'inscription lundi 22 octobre 2007 Statut Membre Dernière intervention 1 novembre 2011 - 7 août 2008 à 22:18
Bonjour !

Je n'arrive pas à trouver d'éxplications claires quand à l'utilisation de sendinput en vb.net.

La conversion de vb6 à v.net étant périeuse, je me réfere à vous pour me donner des éxemples d'utilisation.

Merci d'avance !

4 réponses

cs_devoluti0n Messages postés 22 Date d'inscription lundi 14 mars 2005 Statut Membre Dernière intervention 14 juin 2008
9 avril 2007 à 10:56
S'il vous plait ? je fais tous les forums à la recherche d'une ame charitable :)
0
cs_devoluti0n Messages postés 22 Date d'inscription lundi 14 mars 2005 Statut Membre Dernière intervention 14 juin 2008
9 avril 2007 à 17:54
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 :(
0
cs_devoluti0n Messages postés 22 Date d'inscription lundi 14 mars 2005 Statut Membre Dernière intervention 14 juin 2008
10 avril 2007 à 09:37
SVP ^^
0
werdDomain Messages postés 60 Date d'inscription lundi 22 octobre 2007 Statut Membre Dernière intervention 1 novembre 2011
7 août 2008 à 22:18
Tu obtien surment une erreur ex "Debalencement de la pile ..." ou declaration non conforme

 la conversion de Long, de vb6, dans les declarations api, est le type Integer,

pour la conversion de type, tu peut utiliser Ctype, comme sa:

dim I as Intptr = 0&
dim O as object = i 'la conversion de I à O ne retourne aucune erreur
dim II as Intptr = O 'Ici la conversion retourne une erreur, voici comment faire :

dim II as Intptr = Ctype(O, Intptr) 'Ctype(Expresion as Object, Type as Type)as Object
'ne retourneras pas d'erreur

jespere t'avoir aider unpeut dans ta conversion :p
0
Rejoignez-nous