IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

VB.NET Discussion :

sendinput


Sujet :

VB.NET

  1. #1
    Membre confirmé
    Profil pro
    Inscrit en
    Janvier 2006
    Messages
    189
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2006
    Messages : 189
    Par défaut sendinput
    Bonsoir !!

    J'aurai besoin de votre aide car je dois utiliser sendinput et je ne comprends pas comment m'y prendre, car je ne trouve pas d'éxemple concret en vb.net.

    Donc si quelqu'un d'aimable pourai me montrer comment sa fonctionne avec quelque chose de simple, tel que la préssion touche quelquonque, ce serai génial vu que je galere pour trouver !!
    Merci d'avance !!!!

  2. #2
    Membre confirmé
    Inscrit en
    Janvier 2007
    Messages
    201
    Détails du profil
    Informations personnelles :
    Âge : 80

    Informations forums :
    Inscription : Janvier 2007
    Messages : 201
    Par défaut
    Bonjour,
    Google donne pléthore de réponses pour sendinput.
    Bonne chance

  3. #3
    Membre confirmé
    Profil pro
    Inscrit en
    Janvier 2006
    Messages
    189
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2006
    Messages : 189
    Par défaut
    J'y ai déja jeté un coup d'oeil, le souci étant que ces codes sont utilisé pour faire des choses bien précisément, seulement ne savant pas trier les éléments j'en viens à vous demander votre aide.

    J'ai réelement besoin de vous, j'ai fait les déclarations suivantes :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
        Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Integer) As Short
        Private Declare Function SendInput Lib "user32.dll" (ByVal nInputs As Long, ByVal pInputs As GENERALINPUT, ByVal cbSize As Long) As Long
        Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (ByVal pDst As IntPtr, ByVal pSrc As KEYBDINPUT, ByVal ByteLen As Long)
        Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
        Dim genInput(0 To 1) As GENERALINPUT
        Dim keyInput As KEYBDINPUT
     
     
        Private Const VK_CTRL As Long = &HA2
        Private Const VK_SPACE As Long = 32
        Private Const KEYEVENTF_EXTENDEDKEY As Long = &H1
        Private Const KEYEVENTF_KEYUP As Long = &H2
        Const INPUT_MOUSE As Integer = 0
        Const INPUT_KEYBOARD As Integer = 1
        Const INPUT_HARDWARE As Integer = 2
        Structure KEYBDINPUT
            Dim wVk As Integer
            Dim wScan As Integer
            Dim dwFlags As Long
            Dim time As Long
            Dim dwExtraInfo As Long
        End Structure
        Structure HARDWAREINPUT
            Dim uMsg As Long
            Dim wParamL As Integer
            Dim wParamH As Integer
        End Structure
        Structure GENERALINPUT
            Dim dwType As Long
            Dim xi() As Byte
        End Structure
    et le code de mon timer que j'appele par un clic sur un bouton :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
     
        Private Sub Timer1_Tick(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Timer1.Tick
            If GetAsyncKeyState(VK_CTRL) Then
                Dim GInput(0 To 1) As GENERALINPUT
                Dim KInput As KEYBDINPUT
                KInput.wVk = VK_SPACE 'the key we're going to press
                KInput.dwFlags = 0 'press the key
                'copy the structure into the input array's buffer.
                GInput(0).dwType = INPUT_KEYBOARD ' keyboard input
                CopyMemory(GInput(0).xi(0), KInput, Len(KInput))
                'do the same as above, but for releasing the key
     
                'send the input now
                Call SendInput(2, GInput(0), Len(GInput(0)))
     
                Sleep(100)
     
     
                KInput.wVk = VK_SPACE ' the key we're going to realease
                KInput.dwFlags = KEYEVENTF_KEYUP ' release the key
                GInput(1).dwType = INPUT_KEYBOARD ' keyboard input
                CopyMemory(GInput(1).xi(0), KInput, Len(KInput))
                Call SendInput(2, GInput(1), Len(GInput(1)))
            End If
        End Sub
    Et bien sur sa ne marche pas !! le but étant donc que par préssion de ctrl, ce soit Espace qui soit simuler via sendinput.

    A l'aide !

  4. #4
    Membre confirmé
    Profil pro
    Inscrit en
    Janvier 2006
    Messages
    189
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2006
    Messages : 189
    Par défaut
    Aller s'il vous plait !

    J'ai juste besoin qu'on m'aide à changer sa :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
     
    ' 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 :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
     
    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 :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
                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
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    xi(0 To 23) As Byte
    En 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

Discussions similaires

  1. Problèmes avec keybd_event et SendInput
    Par thebarbarius dans le forum Windows
    Réponses: 1
    Dernier message: 30/07/2011, 11h02
  2. SendInput vers un application SDL
    Par 3uclide dans le forum C++
    Réponses: 2
    Dernier message: 24/01/2011, 11h20
  3. Réponses: 2
    Dernier message: 30/06/2010, 15h22
  4. probleme SendInput() clavier virtuel
    Par developpus dans le forum MFC
    Réponses: 2
    Dernier message: 08/05/2009, 04h03
  5. [Interop][C#]SendInput à partir de TextBox
    Par DonkeyMaster dans le forum C++/CLI
    Réponses: 2
    Dernier message: 30/12/2007, 09h18

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo