-
Aug 9th, 2014, 06:49 PM
#1
Thread Starter
New Member
[RESOLVED] Help with getting MousePosition
I originally wrote my application using cursor.position and the outcome was the same. The app displays a representation of the mouse movements, an works beautifully, until the game hooks the mouse. It seems to display a fraction of the actual movement while in game, so it's working, barely. It's hard to explain, so I have uploaded a short clip of it in action in and out of game. Code below, any suggestions regarding this problem appreciated
======================================
Info regarding this thread's closure (and eventual re-approval):
As for the app in question, it is not a hack, it's a streaming overlay (if you check the channel that video is on, I'm a youtuber/streamer). The purpose of the app is so that people can see my keypresses/mouse movements during flight. Subscribers have requested this of me multiple times, and any programs I found out there only displayed keypresses, so I am writing my own solution. So the graphic representations of key presses and mouse movements you see in the gameplay video are actually an overlay on the stream, they are not actually in game, I do not see them during play, only my viewers see it. The app used to apply the overlay on the video stream is OBS (Open Broadcast Software).
======================================
Video comparison of MousePosition in action in Windows, and then in-game:
Form Code:
Code:
Public Class Form1
Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As System.Windows.Forms.Keys) As Short
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim resultS As Short = GetAsyncKeyState(Keys.S)
Dim resultA As Short = GetAsyncKeyState(Keys.A)
Dim resultD As Short = GetAsyncKeyState(Keys.D)
Dim resultW As Short = GetAsyncKeyState(Keys.W)
Dim resultSPC As Short = GetAsyncKeyState(Keys.Space)
Dim resultSHFT As Short = GetAsyncKeyState(Keys.LShiftKey)
Dim Pressed As Color = Color.Cyan
Dim ReleasedBG As Color = Color.Black
Dim Released As Color = Color.DarkSlateGray
If (resultS And 1) = 1 Then
If (resultS And Short.MinValue) = Short.MinValue Then
LBLS.ForeColor = Pressed
LBLS.BackColor = Released
Else
LBLS.ForeColor = Released
LBLS.BackColor = ReleasedBG
End If
Else
If (resultS And Short.MinValue) = Short.MinValue Then
LBLS.ForeColor = Pressed
LBLS.BackColor = Released
Else
LBLS.ForeColor = Released
LBLS.BackColor = ReleasedBG
End If
End If
If (resultA And 1) = 1 Then
If (resultA And Short.MinValue) = Short.MinValue Then
LBLA.ForeColor = Pressed
LBLA.BackColor = Released
Else
LBLA.ForeColor = Released
LBLA.BackColor = ReleasedBG
End If
Else
If (resultA And Short.MinValue) = Short.MinValue Then
LBLA.ForeColor = Pressed
LBLA.BackColor = Released
Else
LBLA.ForeColor = Released
LBLA.BackColor = ReleasedBG
End If
End If
If (resultW And 1) = 1 Then
If (resultW And Short.MinValue) = Short.MinValue Then
LBLW.ForeColor = Pressed
LBLW.BackColor = Released
Else
LBLW.ForeColor = Released
LBLW.BackColor = ReleasedBG
End If
Else
If (resultW And Short.MinValue) = Short.MinValue Then
LBLW.ForeColor = Pressed
LBLW.BackColor = Released
Else
LBLW.ForeColor = Released
LBLW.BackColor = ReleasedBG
End If
End If
If (resultD And 1) = 1 Then
If (resultD And Short.MinValue) = Short.MinValue Then
LBLD.ForeColor = Pressed
LBLD.BackColor = Released
Else
LBLD.ForeColor = Released
LBLD.BackColor = ReleasedBG
End If
Else
If (resultD And Short.MinValue) = Short.MinValue Then
LBLD.ForeColor = Pressed
LBLD.BackColor = Released
Else
LBLD.ForeColor = Released
LBLD.BackColor = ReleasedBG
End If
End If
If (resultSPC And 1) = 1 Then
If (resultSPC And Short.MinValue) = Short.MinValue Then
LBLSPC.ForeColor = Pressed
LBLSPC.BackColor = Released
Else
LBLSPC.ForeColor = Released
LBLSPC.BackColor = ReleasedBG
End If
Else
If (resultSPC And Short.MinValue) = Short.MinValue Then
LBLSPC.ForeColor = Pressed
LBLSPC.BackColor = Released
Else
LBLSPC.ForeColor = Released
LBLSPC.BackColor = ReleasedBG
End If
End If
If (resultSHFT And 1) = 1 Then
If (resultSHFT And Short.MinValue) = Short.MinValue Then
LBLSHFT.ForeColor = Pressed
LBLSHFT.BackColor = Released
Else
LBLSHFT.ForeColor = Released
LBLSHFT.BackColor = ReleasedBG
End If
Else
If (resultSHFT And Short.MinValue) = Short.MinValue Then
LBLSHFT.ForeColor = Pressed
LBLSHFT.BackColor = Released
Else
LBLSHFT.ForeColor = Released
LBLSHFT.BackColor = ReleasedBG
End If
End If
EpicDot.Left = MousePosition.X / 10 + MD.Left - (EpicDot.Width / 2)
EpicDot.Top = MousePosition.Y / 10 + MD.Top - (EpicDot.Height)
If Fader1.FillStyle = PowerPacks.FillStyle.Percent20 Then
Fader1.FillStyle = PowerPacks.FillStyle.Solid
Fader1.Top = EpicDot.Top
Fader1.Left = EpicDot.Left
ElseIf Fader1.FillStyle = PowerPacks.FillStyle.Solid Then
Fader1.FillStyle = PowerPacks.FillStyle.Percent80
ElseIf Fader1.FillStyle = PowerPacks.FillStyle.Percent80 Then
Fader1.FillStyle = PowerPacks.FillStyle.Percent60
ElseIf Fader1.FillStyle = PowerPacks.FillStyle.Percent60 Then
Fader1.FillStyle = PowerPacks.FillStyle.Percent40
ElseIf Fader1.FillStyle = PowerPacks.FillStyle.Percent40 Then
Fader1.FillStyle = PowerPacks.FillStyle.Percent20
End If
If Fader2.FillStyle = PowerPacks.FillStyle.Percent20 Then
Fader2.FillStyle = PowerPacks.FillStyle.Solid
Fader2.Top = EpicDot.Top
Fader2.Left = EpicDot.Left
ElseIf Fader2.FillStyle = PowerPacks.FillStyle.Solid Then
Fader2.FillStyle = PowerPacks.FillStyle.Percent80
ElseIf Fader2.FillStyle = PowerPacks.FillStyle.Percent80 Then
Fader2.FillStyle = PowerPacks.FillStyle.Percent60
ElseIf Fader2.FillStyle = PowerPacks.FillStyle.Percent60 Then
Fader2.FillStyle = PowerPacks.FillStyle.Percent40
ElseIf Fader2.FillStyle = PowerPacks.FillStyle.Percent40 Then
Fader2.FillStyle = PowerPacks.FillStyle.Percent20
End If
If Fader3.FillStyle = PowerPacks.FillStyle.Percent20 Then
Fader3.FillStyle = PowerPacks.FillStyle.Solid
Fader3.Top = EpicDot.Top
Fader3.Left = EpicDot.Left
ElseIf Fader3.FillStyle = PowerPacks.FillStyle.Solid Then
Fader3.FillStyle = PowerPacks.FillStyle.Percent80
ElseIf Fader3.FillStyle = PowerPacks.FillStyle.Percent80 Then
Fader3.FillStyle = PowerPacks.FillStyle.Percent60
ElseIf Fader3.FillStyle = PowerPacks.FillStyle.Percent60 Then
Fader3.FillStyle = PowerPacks.FillStyle.Percent40
ElseIf Fader3.FillStyle = PowerPacks.FillStyle.Percent40 Then
Fader3.FillStyle = PowerPacks.FillStyle.Percent20
End If
If Fader4.FillStyle = PowerPacks.FillStyle.Percent20 Then
Fader4.FillStyle = PowerPacks.FillStyle.Solid
Fader4.Top = EpicDot.Top
Fader4.Left = EpicDot.Left
ElseIf Fader4.FillStyle = PowerPacks.FillStyle.Solid Then
Fader4.FillStyle = PowerPacks.FillStyle.Percent80
ElseIf Fader4.FillStyle = PowerPacks.FillStyle.Percent80 Then
Fader4.FillStyle = PowerPacks.FillStyle.Percent60
ElseIf Fader4.FillStyle = PowerPacks.FillStyle.Percent60 Then
Fader4.FillStyle = PowerPacks.FillStyle.Percent40
ElseIf Fader4.FillStyle = PowerPacks.FillStyle.Percent40 Then
Fader4.FillStyle = PowerPacks.FillStyle.Percent20
End If
If Fader5.FillStyle = PowerPacks.FillStyle.Percent20 Then
Fader5.FillStyle = PowerPacks.FillStyle.Solid
Fader5.Top = EpicDot.Top
Fader5.Left = EpicDot.Left
ElseIf Fader5.FillStyle = PowerPacks.FillStyle.Solid Then
Fader5.FillStyle = PowerPacks.FillStyle.Percent80
ElseIf Fader5.FillStyle = PowerPacks.FillStyle.Percent80 Then
Fader5.FillStyle = PowerPacks.FillStyle.Percent60
ElseIf Fader5.FillStyle = PowerPacks.FillStyle.Percent60 Then
Fader5.FillStyle = PowerPacks.FillStyle.Percent40
ElseIf Fader5.FillStyle = PowerPacks.FillStyle.Percent40 Then
Fader5.FillStyle = PowerPacks.FillStyle.Percent20
End If
End Sub
End Class
Last edited by JMcIvor; Aug 11th, 2014 at 03:24 PM.
-
Aug 11th, 2014, 03:25 PM
#2
Thread Starter
New Member
Re: Help with getting MousePosition
Hi everybody!
My thread has been re-opened, but while it was closed for suspected UAP violation (It was though that I was making a malicious application) it fell into the nether-regions, so I am giving it a bump for possible help
-
Aug 11th, 2014, 09:35 PM
#3
Thread Starter
New Member
Re: Help with getting MousePosition
We'll I've tried:
Windows.Forms.Cursor.Position.X
MousePosition.X
Cursor.Position
Control.MousePosition.X
I'm at a loss here
-
Sep 10th, 2014, 09:16 PM
#4
Thread Starter
New Member
Re: Help with getting MousePosition
Not that anybody would be interested, but in responsibly concluding a thread, I'll post the outcome.
I've finished this application (a while ago). I eventually gave up on getting the actual current position of the mouse, as it doesnt grab the actual position as given by the device, it gives the position of the cursor, regardless of what is done. Being an FPS game, the cursor is almost always true center of screen (resolution x / 2 and y / 2). So what I did was make 4 images that fire their .Visible properties to false and true depending on comparing cursor position (which did move slightly, even though there was no cursor) as demonstrated in the above video. So instead of a true representation of mouse location, I settled on mouse direction.
Code I wrote for this solution:
Note:
IMG's are picturebox/imagebox
PrevPosX and PrevPosY are variables you need to set to true center of screen (resolution/2)
XTxt and YTxt are text boxes on the GUI (for your current resolution)
Code:
'MODULE CODE:
Module CursorPositionWinAPI
Structure PointAPI
Public x As Int32 ' Integer if you prefer
Public y As Int32 ' Integer if you prefer
End Structure
Public Declare Function GetCursorPos Lib "user32" (ByRef lpPoint As PointAPI) As Boolean
Declare Function ScreenToClient Lib "user32" (ByVal hwnd As Int32, ByRef lpPoint As PointAPI) As Int32
Public Function MouseXposition()
Dim lpPoint As PointAPI
Dim MousePOS As String = GetCursorPos(lpPoint)
Dim MouseX As String = CStr(lpPoint.x)
Return MouseX
End Function
Public Function MouseYposition()
Dim lpPoint As PointAPI
Dim MousePOS As String = GetCursorPos(lpPoint)
Dim MouseY As String = CStr(lpPoint.y)
Return MouseY
End Function
End Module
'FORM CODE (I wrote it for use in a timer)
If (MouseXposition() = PrevPosX) And (MouseYposition() = PrevPosY) Then
IMGDN.Visible = False
IMGUP.Visible = False
IMGLFT.Visible = False
IMGRT.Visible = False
Else
If MouseYposition() > PrevPosY Then
IMGDN.Visible = True
IMGUP.Visible = False
End If
If MouseYposition() < PrevPosY Then
IMGDN.Visible = False
IMGUP.Visible = True
End If
If MouseXposition() > PrevPosX Then
IMGLFT.Visible = False
IMGRT.Visible = True
End If
If MouseXposition() < PrevPosX Then
IMGLFT.Visible = True
IMGRT.Visible = False
End If
If IsNumeric(XTXT.Text) Then
XTXT.Text = Trim(XTXT.Text)
PrevPosX = XTXT.Text / 2
Label7.Visible = False
Else
Label7.Visible = True
End If
If IsNumeric(YTXT.Text) Then
YTXT.Text = Trim(YTXT.Text)
PrevPosY = YTXT.Text / 2
Label7.Visible = False
Else
Label7.Visible = True
End If
End If
See it in use in this video (Bottom right of the video)
Last edited by JMcIvor; Sep 10th, 2014 at 09:19 PM.
Reason: Added video of the overlay in use
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|