Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Confused by _buttonchange
#1
I'm trying to understand how to use  _ButtonChange in a prog, but this gives Illegal Function error at line 3. Any idea why please?
(I know there are other ways to detect a mousekey, I just want to get this one nailed).

i = _MouseInput
Do
    change% = _ButtonChange(1%)
    Locate 1, 1: Print change%
Loop
Of all the places on Earth, and all the planets in the Universe, I'd rather live here (Perth, Western Australia.) Big Grin
Please visit my Website at: http://oldendayskids.blogspot.com/
Reply
#2
Never used it before, but you have to add the device code...

Code: (Select All)
Do
    _Limit 30
    While _MouseInput: Wend
    If _MouseButton(1) Then Exit Do
Loop
d& = _DeviceInput
If d& Then
    Print _ButtonChange(1)
End If

So that gets rid of the error, but I haven't had an interest in it, so I can't provide a practical use.

Oh, Okay, looking at it a bit more and...

Code: (Select All)
Do
_Limit 30
While _MouseInput: Wend
d& = _DeviceInput
If d& Then
For b = 1 To _LastButton(d&)
If _ButtonChange(b) Then
Print "Button Number:"; b, "Status:"; _Button(b), "Change:"; _ButtonChange(b), "Number of Buttons:"; _LastButton(d&)
End If
Next
End If
Loop

Pete
Shoot first and shoot people who ask questions, later.
Reply
#3
Sorry Pete, still don't get it. Doesn't my _MouseInput line at the top specify the device?
Of all the places on Earth, and all the planets in the Universe, I'd rather live here (Perth, Western Australia.) Big Grin
Please visit my Website at: http://oldendayskids.blogspot.com/
Reply
#4
_ButtonChange isn't a _MOUSE routine; it's _DEVICES.   

Code: (Select All)
read_Devices = _Devices 'You need this to init the devices first
Do
    _Limit 30
    d& = _DeviceInput
    If d& = 1 Then 'd now tells you WHERE you had an input event
        '1 is a keyboard event
        For b = 1 To _LastButton(d&)
            If _ButtonChange(b) Then
                Print "Keyboard Key Number:"; b, "Status:"; _Button(b), "Change:"; _ButtonChange(b)
            End If
        Next
    ElseIf d& = 2 Then
        '2 is a mouse event
        For b = 1 To _LastButton(d&)
            If _ButtonChange(b) Then
                Print "Button Number:"; b, "Status:"; _Button(b), "Change:"; _ButtonChange(b)
            End If
        Next
    ElseIf d& = 3 Then
        '2 is a joystick event
        For b = 1 To _LastButton(d&)
            If _ButtonChange(b) Then
                Print "Joystick Number:"; b, "Status:"; _Button(b), "Change:"; _ButtonChange(b)
            End If
        Next
    End If
Loop

Notice with the above it tells you if you hit the keyboard, mouse, or joystick, and which button you hit.

Also note that _DEVICES maps to the physical keys on your keyboard and NOT any ASCII codes.   Hit "A" and it'll report a value of 31, not a value of 65.

And did you notice?  It gives you mouse results with no WHILE _MOUSEINPUT in play anywhere.

It's a completely different input system, just as _KEYHIT and INKEY$ use different buffers and aren't related.
Reply
#5
Nice, that means I can reduce my code to...

Code: (Select All)
Do
    _Limit 30
    d& = _DeviceInput
    If d& Then
        For b = 1 To _LastButton(d&)
            If _ButtonChange(b) Then
                Print "Button Number:"; b, "Status:"; _Button(b), "Change:"; _ButtonChange(b), "Number of Buttons:"; _LastButton(d&)
            End If
        Next
    End If
Loop

What I like about this method is not the _ButtonChange(), but the status obtained using _Button(). I could use this method to abbreviate my current universal mouse routine, which relies on a routine to obtain a change in button status.

Pete
Reply
#6
"_ButtonChange isn't a _MOUSE routine; it's _DEVICES."

So mouse is not a device?

edit: Ah, I think I get it... it aplies to All devices, so you need to tell __ButtonChange which device, right?. Sorry.
Of all the places on Earth, and all the planets in the Universe, I'd rather live here (Perth, Western Australia.) Big Grin
Please visit my Website at: http://oldendayskids.blogspot.com/
Reply
#7
The wheel on the mouse goes round and round
Round and round
Round and round
The wheel on the mouse goes round and round
All day long...

- Loony Tunes
Reply
#8
(09-06-2025, 03:49 AM)Pete Wrote: The wheel on the mouse goes round and round
Round and round
Round and round
The wheel on the mouse goes round and round
All day long...

- Loony Tunes

The buttons on the mouse go click, click, click...
(while we're doing ridiculosity...)  Big Grin
Of all the places on Earth, and all the planets in the Universe, I'd rather live here (Perth, Western Australia.) Big Grin
Please visit my Website at: http://oldendayskids.blogspot.com/
Reply
#9
(09-06-2025, 03:28 AM)PhilOfPerth Wrote: "_ButtonChange isn't a _MOUSE routine; it's _DEVICES."

So mouse is not a device?

edit: Ah, I think I get it... it aplies to All devices, so you need to tell __ButtonChange which device, right?. Sorry.

Yeah, a mouse is a device.  Your keyboard is a device.  The joystick is a device.   To use the command successfully, you first need to make certain which device you had input on, and THEN deal with that input.

Also note that the mouse is NOT always the 2nd device.  You really should check for which device is which, before just assuming anything.

For example, on my laptop, I have:

1) laptop keyboard
2) full size bluetooth keyboard
3) trackpad
4) bluetooth trackball
5) joystick
6) joystick

So if I were to just code with the assumption that I had 1) keyboard 2) mouse 3) joystick, I'd be screwing up on all sorts of device events.
Reply
#10
The important thing is to never attach your nuts to your laptop. I did that once, and they got caught in device.

Pete Big Grin  - click, click, click...
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)