Buenas alguien conoce una api o alternativa a keybd_event (Que no sea SendKeys o SendMessage)
SAludos.
bueno parce que SendInput es la alternativa, aun no lo pruevo, este es un ejemplo del api guide pero no logro liberarme del Copymemory, ...
sigo devajo
Const VK_H = 72
Const VK_E = 69
Const VK_L = 76
Const VK_O = 79
Const KEYEVENTF_KEYUP = &H2
Const INPUT_MOUSE = 0
Const INPUT_KEYBOARD = 1
Const INPUT_HARDWARE = 2
Private Type MOUSEINPUT
dx As Long
dy As Long
mouseData As Long
dwFlags As Long
time As Long
dwExtraInfo As Long
End Type
Private Type KEYBDINPUT
wVk As Integer
wScan As Integer
dwFlags As Long
time As Long
dwExtraInfo As Long
End Type
Private Type HARDWAREINPUT
uMsg As Long
wParamL As Integer
wParamH As Integer
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)
Private Sub Form_KeyPress(KeyAscii As Integer)
'Print the key on the form
Me.Print Chr$(KeyAscii);
End Sub
Private Sub Form_Paint()
'KPD-Team 2000
'URL: http://www.allapi.net/
'E-Mail: KPDTeam@Allapi.net
'Clear the form
Me.Cls
'call the SendKey-function
SendKey VK_H
SendKey VK_E
SendKey VK_L
SendKey VK_L
SendKey VK_O
End Sub
Private Sub SendKey(bKey As Byte)
Dim GInput(0 To 1) As GENERALINPUT
Dim KInput As KEYBDINPUT
KInput.wVk = bKey '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
KInput.wVk = bKey ' 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)
'send the input now
Call SendInput(2, GInput(0), Len(GInput(0)))
End Sub
al parecer esta api trabja con diferentes extructuras y los del apiguide para generalizar utilizaron un array de bits para copiar la extructura a este, yo solo voy a utilizar KEYBDINPUT lo que no entiendo no me funciona si uilizo esta estructura de esta forma
Private Type tINPUT
dwType As Long
ki As KEYBDINPUT
End Type
si bien ellos redimencionan el array a 24 bits KEYBDINPUT tiene como largo 32 bits
bueno en fin sigo probando hasta que salga. si alguien puede que chifle.
saludos.
Modifica
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 as KEYBDINPUT '<------ aca
End Type
eso tendria que arreglarlo si solamente queres el keyboard
Puedo preguntar por que intentas evitar keybd_event()? :P
Cita de: cobein en 6 Enero 2011, 06:34 AM
Modifica
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 as KEYBDINPUT '<------ aca
End Type
eso tendria que arreglarlo si solamente queres el keyboard
Hola Cobein probe de esa forma pero no funciono, para que ande tube que agregar ocho byte mas para completar los 24 bytes
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 As KEYBDINPUT
Relleno(0 To 7) As Byte '<------ aca
End Type
@Karcrack
Es una mejora para el "escritorio remoto", no me funcionaba bien las partes de las pulsaciones, no te explico con detalles porque es un chivo largo, pero bueno la idea es buscar un sustituto haber si mejora la cosa.
Saludos y gracias por todo