multibutton tip
Author |
Message |
ttm
|
Posted: Sat Jan 07, 2012 12:34 pm Post subject: multibutton tip |
|
|
First, multibutton is broken. Proof:
It always only shows either 1, 10, or 100. According to the documentation, it should show values such as 101 when you left and right click simultaneously.
The tutorial part:
I realized that you could take the button value mod 8, and bit 0 of the result would be if you left clicked, bit 1 would be if you middle clicked, and bit 2 would be if you right clicked. But since it's broken, this tip is temporarily useless until it gets fixed. |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Dreadnought
|
Posted: Sat Jan 07, 2012 5:23 pm Post subject: Re: multibutton tip |
|
|
When life gives you lemons, grow your own oranges to make orange juice!
Turing: | Mouse.ButtonChoose ("multibutton")
View.Set ("offscreenonly")
const Buttons : array 1 .. 3 of string := init ("Left", "Middle", "Right")
var x, y, btnNumber, DummyVar : int
var ButtonPressed : array 1 .. 3 of boolean := init (false, false, false)
loop
if Mouse.ButtonMoved ("down") then
Mouse.ButtonWait ("down", DummyVar, DummyVar, btnNumber, DummyVar )
ButtonPressed (btnNumber ) := true
end if
if Mouse.ButtonMoved ("up") then
Mouse.ButtonWait ("up", DummyVar, DummyVar, btnNumber, DummyVar )
ButtonPressed (btnNumber ) := false
end if
Mouse.Where (x, y, DummyVar )
cls
put "Mouse is at x: ", x, " and y: ", y
for but : 1 .. 3
if ButtonPressed (but ) then
put "The ", Buttons (but ), " button is pressed."
end if
end for
View.Update
end loop |
Hope this helps you! |
|
|
|
|
|
ttm
|
Posted: Sun Jan 08, 2012 1:08 pm Post subject: Re: multibutton tip |
|
|
(y) |
|
|
|
|
|
ttm
|
Posted: Sun Jan 08, 2012 1:29 pm Post subject: Re: multibutton tip |
|
|
It doesn't work when the mouse is outside of the window though. |
|
|
|
|
|
Dreadnought
|
Posted: Sun Jan 08, 2012 5:23 pm Post subject: Re: multibutton tip |
|
|
ttm wrote:
It doesn't work when the mouse is outside of the window though.
That's true, when the turing window is not active it does not receive mouse events. Most of the time, this shouldn't be too much of a problem since you don't click outside the Turing window to do stuff in the Turing window.
Here's an update to my previous code using Mouse.Where to the best of its ability (like you showed it's not functioning properly):
Turing: | Mouse.ButtonChoose ("multibutton")
View.Set ("offscreenonly")
const Buttons : array 1 .. 3 of string := init ("Left", "Middle", "Right")
var x, y, btnNumber, DummyVar, ButtonCheck, ButtonLast : int := 0
var ButtonPressed : array 1 .. 3 of boolean := init (false, false, false)
loop
if Mouse.ButtonMoved ("down") then
Mouse.ButtonWait ("down", DummyVar, DummyVar, btnNumber, DummyVar )
ButtonPressed (btnNumber ) := true
end if
if Mouse.ButtonMoved ("up") then
Mouse.ButtonWait ("up", DummyVar, DummyVar, btnNumber, DummyVar )
ButtonPressed (btnNumber ) := false
end if
Mouse.Where (x, y, ButtonCheck )
cls
put "Mouse is at x: ", x, " and y: ", y
if ButtonCheck ~ = ButtonLast then % Extra check for when the mouse is outside the window.
for but : 1 .. 3
if ButtonCheck = 0 or ButtonCheck > 10 ** (but - 1) then
ButtonPressed (but ) := false
elsif ButtonCheck = 10 ** (but - 1) then
ButtonPressed (but ) := true
end if
end for
ButtonLast := ButtonCheck
end if
for but : 1 .. 3
if ButtonPressed (but ) then
put "The ", Buttons (but ), " button is pressed."
end if
end for
View.Update
end loop |
Overall, it seems we can't get full information about mouse buttons when the mouse is not in an active Turing window. On the other hand, this should rarely be troublesome as you don't tend to care about mouse input when the mouse is not in the window. |
|
|
|
|
|
|
|