Anyone know how to use the Mouse.State property?
From the wiki...
Mouse.State (gb.qt4)
Static Property Read State As Integer
Return the state of the mouse buttons when the mouse event was generated.
The state is an integer whose each bit represents the state of one button.
The bit 0 is set if the left button is pressed.
The bit 1 is set if the middle button is pressed.
The bit 2 is set if the right button is pressed.
But i have no idea how to inspect the bits.
I've tried using Lsl Lsr Shl Shr but it's all very confusing
Cheers
getting bits from an integer (Mouse.State)
- BruceSteers
- Posts: 1581
- Joined: Thursday 23rd July 2020 5:20pm
- Location: Isle of Wight
- Contact:
getting bits from an integer (Mouse.State)
If at first you don't succeed , try doing something differently.
BruceS
BruceS
Re: getting bits from an integer (Mouse.State)
...by using Bin() function:
https://gambaswiki.org/wiki/lang/bin
Public Sub Form_MouseDown()
Print Bin(Mouse.State, 8)
End
https://gambaswiki.org/wiki/lang/bin
Europaeus sum !
Amare memorentes atque deflentes ad mortem silenter labimur.
Amare memorentes atque deflentes ad mortem silenter labimur.
Re: getting bits from an integer (Mouse.State)
Use the AND
If (Mouse.State AND 1) then the left button was pressed.
If (Mouse.State AND 2) then the middle button was pressed.
If (Mouse.State AND 4) then the right button was pressed.
If (Mouse.State AND 3) then the left and middle buttons were pressed.
If (Mouse.State AND 5) then the middle and right buttons were pressed.
If (Mouse.State AND 7) then all the buttons were pressed.
If (Mouse.State AND 0) then no button was pressed.
If you go any further then you must have one of those weirdo gaming mouses that look like ski bindings.
This is called "bit masking", its been around since Ada Lovelace was playing with dollies. I am quite staggered that you dont know it.
For the sake of simplicity lets use a four bit machine. It is capable of counting up to 15!
0000 = 0
0001 = 1
0010 = 2
...
1111 = 15
So the code
LDA @some memory address which is our state variable to be tested.
AND 2
tests if the 2nd bit from the right is set.
bit like tabulature really,
If (Mouse.State AND 1) then the left button was pressed.
If (Mouse.State AND 2) then the middle button was pressed.
If (Mouse.State AND 4) then the right button was pressed.
If (Mouse.State AND 3) then the left and middle buttons were pressed.
If (Mouse.State AND 5) then the middle and right buttons were pressed.
If (Mouse.State AND 7) then all the buttons were pressed.
If (Mouse.State AND 0) then no button was pressed.
If you go any further then you must have one of those weirdo gaming mouses that look like ski bindings.
This is called "bit masking", its been around since Ada Lovelace was playing with dollies. I am quite staggered that you dont know it.
For the sake of simplicity lets use a four bit machine. It is capable of counting up to 15!
0000 = 0
0001 = 1
0010 = 2
...
1111 = 15
So the code
LDA @some memory address which is our state variable to be tested.
AND 2
tests if the 2nd bit from the right is set.
bit like tabulature really,
Have you ever noticed that software is never advertised using the adjective "spreadable".
- BruceSteers
- Posts: 1581
- Joined: Thursday 23rd July 2020 5:20pm
- Location: Isle of Wight
- Contact:
Re: getting bits from an integer (Mouse.State)
Thank you guys ,
I was clueless there.
Good to know
I was clueless there.
Good to know
If at first you don't succeed , try doing something differently.
BruceS
BruceS