getting bits from an integer (Mouse.State)
Posted
#1
(In Topic #1185)
Guru

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
Posted
Regular

Posted
Regular

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,
Posted
Guru

I was clueless there.
Good to know
1 guest and 0 members have just viewed this.


