Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Updating my mouse and keyboard routine.
#5
maybe I should post this in my own section

or maybe I should try to get this thread back on topic

here is my single blade knife for just getting a mouse click without backfire from not getting clear of mouse button release at next mouse poll or mouse catching missed because a single keydown was not responeded to fast enough and another detection (the same mouse down causes a reverse because my app is toggle a cell on or off. This is same situation that arose in dbox Play demo of Play.

Code: (Select All)
_Title "ClickTF test on grid" ' b+ 2025-01-20 test Steve mouse catch click with OldMouse check

Dim Shared As Long SW, SH
SW = 800: SH = 600
Screen _NewImage(SW, SH, 32): _ScreenMove 210, 60
sq = 100 ' cellsize in pixels 100x100 and xoffset and yoffset
cellsAcross = 6: CellsDown = 4
drawGrid sq, sq, sq, sq, cellsAcross, CellsDown ' OK

' now test clicking the cells
Do
    If ClickTF%(mx, my) Then ' covert mx, my to a grid cell or say not in grid
        gridx = mx \ sq: gridY = my \ sq
        Locate 1, 1: Print Space$(500); ' clear line
        Locate 1, 1: Print gridx; ","; gridY;
        Print _IIf(gridx > 0 And gridx <= cellsAcross And gridY > 0 And gridY <= CellsDown, "inside", "outside");_
         " the grid."
    End If
Loop

Function ClickTF% (mx, my) ' where the mouse button goes down at NOT after any drag!
    Static OldMouse: Dim mb  
    While _MouseInput: Wend ' there we've polled the mouse we don't need to remain inside the loop unless we need mouse wheel
    mb = _MouseButton(1)
    If mb And Not OldMouse Then
        mx = _MouseX: my = _MouseY: ClickTF% = -1
    End If
    OldMouse = mb
End Function

Sub drawGrid (x, y, xs, ys, xn, yn) ' top left x, y, x side, y side, number of x, nmber of y
    Dim As Long i, dx, dy
    dx = xs * xn: dy = ys * yn
    For i = 0 To xn
        Line (x + xs * i, y)-(x + xs * i, y + dy)
    Next
    For i = 0 To yn
        Line (x, y + ys * i)-(x + dx, y + ys * i)
    Next
End Sub

A useful low LOC routine that is portable to many apps eg boards for editing graphics pixel by pixel or tile by tile, or games.

No more hacky! _Delay .25 yea!
b = b + ...
Reply


Messages In This Thread
RE: Updating my mouse and keyboard routine. - by bplus - 2 hours ago



Users browsing this thread: 7 Guest(s)