Darc Posted August 19, 2003 Posted August 19, 2003 I don't know where I'm supposed to post this but this IS the directx 9 forums so... When i use the mouse, I set it all up and the clicking works fine but every time I try to get the X/Y positions, it returns 0. Any help? Quote
*Experts* Nerseus Posted August 19, 2003 *Experts* Posted August 19, 2003 What code are you using? Can you post a small project? -Nerseus Quote "I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
Darc Posted August 19, 2003 Author Posted August 19, 2003 Here's the clsDIMouse that I made: Option Strict On Option Explicit On Imports Microsoft.DirectX Imports Microsoft.DirectX.DirectInput Public Class clsDIMouse Private frmTarget As Form Private devMouse As Device Private lMouseX As Long Private lMouseY As Long Public Sub New(ByVal frm As Form) frmTarget = frm devMouse = New Device(SystemGuid.Mouse) devMouse.SetDataFormat(DeviceDataFormat.Mouse) devMouse.SetCooperativeLevel(frm, CooperativeLevelFlags.Foreground Or CooperativeLevelFlags.Exclusive) devMouse.Acquire() End Sub Private Function State() As MouseState Try Return devMouse.CurrentMouseState Catch Try devMouse.Acquire() Catch ex As InputException If TypeOf ex Is OtherApplicationHasPriorityException Or TypeOf ex Is NotAcquiredException Then 'check what type of input exception occured Return Nothing End If End Try End Try End Function Public ReadOnly Property MouseX() As Long Get lMouseX = State.X Return lMouseX End Get End Property Public ReadOnly Property MouseY() As Long Get lMouseY += State.Y Return lMouseY End Get End Property Public ReadOnly Property LeftClick() As Boolean Get Dim temp As Byte() = State.GetMouseButtons() If temp(0) <> 0 Then Return True Else Return False End If End Get End Property Public ReadOnly Property RightClick() As Boolean Get Dim temp As Byte() = State.GetMouseButtons() If temp(1) <> 0 Then Return True Else Return False End If End Get End Property Public Function free() As Boolean Try devMouse.Unacquire() devMouse.Dispose() devMouse = Nothing Return True Catch Return False End Try End Function End Class And here's the funtion that sends an object to the mouse (I'm not very good at this kind of math so I copied this from somewhere... I don't know if its the write equation :S) Public Function GoToMouse(ByVal sprPosX As Double, ByVal sprPosY As Double, ByVal sprPosSpeed As Double, ByVal mouseX As Double, ByVal mouseY As Double, ByRef MoveX As Double, ByRef MoveY As Double) As Boolean Try Dim xDiff As Double = CDbl(mouseX - sprPosX) Dim ydiff As Double = CDbl(mouseY - sprPosY) Dim Length As Double = xDiff * xDiff + ydiff * ydiff Length = Sqrt(Length) MoveX = (sprPosX - mouseX) / Length * sprPosSpeed MoveY = (sprPosY - mouseY) / Length * sprPosSpeed Catch End Try End Function Quote
AndreRyan Posted August 20, 2003 Posted August 20, 2003 There is no Return in the GoToMouse Function so you should change it into a Sub since it's always False anyway. When you say "Get X/Y" do you mean clsDIMouse.MouseX and clsDIMouse.MouseY or GoToMouse GoToMouse returns MoveX and MoveY. I think that DirectInput only returns the distance moved (As in move the mouse up then State will be 100[Y] then reset to 0 when the mouse stops) so you may need to track it manually if it still works like this. The documentation is most unhelpful so I can't tell you though. Quote .Net allows software to be written for any version of Windows and not break like Unmanaged applications unless using Unmanaged procedures like APIs. If your program uses large amounts of memory but releases it when something else needs it, then what's the problem?
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.