getting bits from an integer (Mouse.State)

Post

Posted
Rating:
#1 (In Topic #1185)
Guru
BruceSteers is in the usergroup ‘Guru’
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
Online now: No Back to the top

Post

Posted
Rating:
#2
Regular
vuott is in the usergroup ‘Regular’
…by using Bin() function:

Code (gambas)

  1. Public Sub Form_MouseDown()
  2.  
  3.   Print Bin(Mouse.State, 8)
  4.  
/lang/bin - Gambas Documentation

Europaeus sum !

<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
Online now: No Back to the top

Post

Posted
Rating:
#3
Avatar
Regular
thatbruce is in the usergroup ‘Regular’
 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,

Online now: No Back to the top

Post

Posted
Rating:
#4
Guru
BruceSteers is in the usergroup ‘Guru’
Thank you guys ,
I was clueless there.

Good to know :)
Online now: No Back to the top
1 guest and 0 members have just viewed this.