09-26-2023, 10:04 PM
Hi Terry
Hi Steve
Hi all folks
I need an help to be working well to 100% this my QB64 snippet that detects when mouse leaves the area of the application.
Thanks to Steve, Bplus, GrymmJack and all you QB64 coders with your feedbacks and suggestions!
Generally it works ok, but it sometimes lasts stuck and you must repeat the action to get the detection of mouse out of window.
How can it be improved?
Thanks for feedbacks
Hi Steve
Hi all folks
I need an help to be working well to 100% this my QB64 snippet that detects when mouse leaves the area of the application.
Thanks to Steve, Bplus, GrymmJack and all you QB64 coders with your feedbacks and suggestions!
Code: (Select All)
Rem it is a code test to detect mouse out of window of application using only QB64 code
Option _Explicit
Dim As Long S1, W1, H1
Dim As Integer Xm, Ym, Dxm, Dym, Im, Ox, Oy
W1 = 800: H1 = 600
S1 = _NewImage(W1, H1, 32)
Screen S1
Do
Im = _MouseInput
If Im Then
Dxm = _MouseMovementX
Dym = _MouseMovementY
If Dxm Then Xm = IsOutWindow%(0, _Width - 1, Dxm, _MouseX, Ox)
If Dym Then Ym = IsOutWindow%(0, _Height - 1, Dym, _MouseY, Oy)
Select Case Xm
Case 0:
If Ym = 0 Then Print " mouse in window"
Case 1:
Print "mouse out on the right of window"
Case -1:
Print "mouse out on the left of window"
Case Else
End Select
Select Case Ym
Case 1:
Print "mouse out on the bottom of window"
Case -1:
Print " mouse out on the top of window"
Case Else
End Select
Ox = Xm
Oy = Ym
End If
_Limit 300
Loop Until InKey$ <> ""
End
Function IsOutWindow% (Min As Integer, Max As Integer, DeltaMove As Integer, MousePos As Integer, OldMode As Integer)
If MousePos > Min And MousePos < Max Then
' is it in the range of the window?
IsOutWindow% = 0 ': Exit Function
ElseIf DeltaMove > 0 And MousePos = Max Then
' is it moving towards right and it is on the right edge?
IsOutWindow% = 1 ': Exit Function
ElseIf DeltaMove < 0 And MousePos = Min Then
' is it moving towards left and it is on the left edge?
IsOutWindow% = -1 ': Exit Function
ElseIf MousePos = Max And DeltaMove < 0 And OldMode = 1 Then
' is it on the right edge and it is moving to left and it was out on the right?
IsOutWindow% = 1 ': Exit Function
ElseIf MousePos = Min And DeltaMove > 0 And OldMode = -1 Then
' is it on the left edge and it is moving on the right and it was out on the left?
IsOutWindow% = -1 ': Exit Function
End If
End Function
How can it be improved?
Thanks for feedbacks