"J French" <er*****@nowhere.com> skrev i meddelandet
news:40**************@news.btclick.com...
On Mon, 16 Feb 2004 14:37:00 GMT, "BadOmen" <ba*******@hotmail.com>
wrote:
The I am using the "keybd_event" but the mouse buttons does not work,
VK_LBUTTON and VK_RBUTTON does not work, way???
The rest seams to work fine :-)
Mouse_event is for mouse clicks
Keybd_event is for key presses
Ops, thanx
Now I so that Keybd_event and Mouse_event is superseded. I don't really
know what it means, but I think It's best avoiding it.
I am using the SendInput function instead, but I don't really understand how
it works. The msdn is not that simple I think, plus everything I found on
SendInput was written in C/C++.
This is how I am doing it (I found an example and changed it a bit)
Option Explicit
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (pDst As
Any, pSrc As Any, ByVal ByteLen As Long)
Private Declare Function SendInput Lib "user32.dll" (ByVal nInputs As Long,
pInputs As INPUT_TYPE, ByVal cbSize As Long) As Long
Public Enum MouseClick 'Set the constans of the mouse buttons
MOUSEEVENTF_LEFTDOWN = &H2
MOUSEEVENTF_LEFTUP = &H4
MOUSEEVENTF_RIGHTDOWN = &H8
MOUSEEVENTF_RIGHTUP = &H10
MOUSEEVENTF_MIDDLEDOWN = &H20
MOUSEEVENTF_MIDDLEUP = &H40
End Enum
Private Const INPUT_MOUSE = 0
Private Const INPUT_KEYBOARD = 1
Private Const INPUT_HARDWARE = 2
Type MOUSEINPUT
dx As Long
dy As Long
mouseData As Long
dwFlags As Long
dwtime As Long
dwExtraInfo As Long
End Type
'***This I would be niding to make a KeyPress, But I dont know how...
Type KEYBDINPUT
wVk As Integer
wScan As Integer
dwFlags As Long
time As Long
dwExtraInfo As Long
End Type
Type INPUT_TYPE
dwType As Long
xi(0 To 23) As Byte
End Type
Public Sub ClickDaMouse(ButtonPressed As MouseClick, ButtonRelise As
MouseClick)
Dim intX As Integer
Dim inputEvents(0 To 1) As INPUT_TYPE ' holds information about each
event
Dim mouseEvent As MOUSEINPUT ' temporarily hold mouse input info
' Load the information needed to synthesize pressing the mouse button.
mouseEvent.dx = 0 ' no horizontal movement
mouseEvent.dy = 0 ' no vertical movement
mouseEvent.mouseData = 0 ' not needed
mouseEvent.dwFlags = ButtonPressed ' button down
mouseEvent.dwtime = 0 ' use the default
mouseEvent.dwExtraInfo = 0 ' not needed
' Copy the structure into the input array's buffer.
inputEvents(0).dwType = INPUT_MOUSE ' mouse input
CopyMemory inputEvents(0).xi(0), mouseEvent, Len(mouseEvent)
' Do the same as above, but for releasing the mouse button.
mouseEvent.dx = 0 ' no horizontal movement
mouseEvent.dy = 0 ' no vertical movement
mouseEvent.mouseData = 0 ' not needed
mouseEvent.dwFlags = ButtonRelise ' button up
mouseEvent.dwtime = 0 ' use the default
mouseEvent.dwExtraInfo = 0 ' not needed
' Copy the structure into the input array's buffer.
inputEvents(1).dwType = INPUT_MOUSE ' mouse input
CopyMemory inputEvents(1).xi(0), mouseEvent, Len(mouseEvent)
' Now that all the information for the 2 input events has been placed
' into the array, finally send it into the input stream.
intX = SendInput(2, inputEvents(0), Len(inputEvents(0))) ' place the
events into the stream
End Sub
++++++++
I think I can use this keys because with them I don't need to specified a
window to sent the information to:
VK_VOLUME_MUTE = 173
'Windows 2000/XP: Volume Mute key
VK_VOLUME_DOWN = &HAE
'Windows 2000/XP: Volume Down key
VK_VOLUME_UP = &HAF
'Windows 2000/XP: Volume Up key
VK_MEDIA_NEXT_TRACK = 176
'Windows 2000/XP: Next Track key
VK_MEDIA_Prev_TRACK = 177
'Windows 2000/XP: Previous Track key
VK_MEDIA_STOP = 178
'Windows 2000/XP: Stop Media key
VK_MEDIA_PLAY_PAUSE = 179
'Windows 2000/XP: Stop Media key
But I want to be able to send Alt+X or CTRL+4 and Shift+a or something like
that to a specific window not the one that have the focus.
maybe I can use this:
Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal
lpClassName As String, ByVal lpWindowName As String) As Long
WinAMPhWnd = FindWindow("Winamp v1.x", vbNullString)
Than I think if I have understand it correct that WinAMPhWnd is holding the
unique ID for WinAmp in this case, which is what hWnd stands for in some
code???
No I don't know how to use that ID to send a key to that window...???
Yours, Jonas