|
Post by william33 on Jan 28, 2024 13:59:49 GMT
I read the following in the wiki for the _mousebutton function:
So I got now the situation - at least under macOS - that changing to fullscreen seems a kind of "interruption". After changing from windowed to fullscreen after a mouse click, it's a kind of ever lasting click until I do a "real" second click. So how do I correctly clear the mouse input?
The wiki says:
But how to do this correctly?
|
|
|
Post by bplus on Jan 28, 2024 18:02:12 GMT
Ah getting clear of the click without reacting 2 or more times is tricky!
I have some old code that waits after a pos mouseinput event to 0 out before reporting the mouse click location. So mouse x, y are't where your mousebutton went down but where you released the mousbutton in case you go mouse down in one cell but release mousebutton in another cell. This code captures the release cell position.
_Title "Mouse click on grid test by bplus 2018-04-24" 'QB64 version 2017 1106/82 (the day before they switched to version 1.2)
'2018-04-25 add screen test, check RAM usage at 1) or 2) comment out one or other
' Some handy code for board games, requested by Prithak, ' also a STOP THE FAN !!! example
Const xmax = 800 Const ymax = 600
'screen test 1) check RAM usage 'SCREEN _NEWIMAGE(xmax, ymax, 32)
'screen test 2) check RAM usage myCanvas& = _NewImage(800, 600, 32) Screen myCanvas&
_ScreenMove 360, 60
xOffSet = 300: yOffSet = 200: squareSize = 40: nSquaresPerSide = 5 Locate 3, 40: Print "Press escape to quit..." Locate 5, 16: Print "Notice this will report the square you released the left mouse button on." BoxColumn = 0: BoxRow = 0: escape = 0 k$ = " " drawGrid xOffSet, yOffSet, squareSize, nSquaresPerSide While 1 getClick xOffSet, yOffSet, squareSize, nSquaresPerSide, BoxColumn, BoxRow, escape If escape Then Cls: End Line (0, 160)-(xmax, 200), &HFF, BF 'black out last report Locate 11, 38: Print "Grid (x, y) click is (" + LTrim$(Str$(BoxColumn)) + "," + Str$(BoxRow) + ")" Wend
'want the board square bx, by from board with grid xoff, yoff, sq pixels, n x n square board Sub getClick (xoff, yoff, sq, n, bx, by, escape) While 1 test$ = InKey$ If Len(test$) Then If Asc(test$) = 27 Then escape = -1: Exit Sub End If
' get players move ' by mouse 'this might NOT be too intuitive but proper mouse catching demands we wait for mouse button release m = _MouseInput: mb = _MouseButton(1): mx = _MouseX: my = _MouseY If mb Then 'get last place mouse button was down mb = _MouseButton(1): mx = _MouseX: my = _MouseY While mb 'left button down, wait for mouse button release before doing anything as a "click" 'this updates mx, my while waiting for button release m = _MouseInput: mb = _MouseButton(1): mx = _MouseX: my = _MouseY Wend row = (my - yoff) / sq If row > 0 And row < n Then by = Int(row) col = (mx - xoff) / sq If col > 0 And col < n Then bx = Int(col) Exit While Else If mx <> -1 And my <> -1 Then Beep End If Else If mx <> -1 And my <> -1 Then Beep End If End If _Limit 1000 'STOP THE FAN !!!!!!!!!!!!!!!!!!! try this with _LIMIT commented out Wend End Sub
Sub drawGrid (x, y, sq, n) d = sq * n For i = 0 To n Line (x + sq * i, y)-(x + sq * i, y + d) Line (x, y + sq * i)-(x + d, y + sq * i) Next End Sub [\code]
I hope the practical example using a grid hasn't made the issue more complex.
Have no idea how Mac might react but this code has worked fine in windows to today when I rechecked it.
|
|