Mouse button helper function for y'all!

Blitz3D Forums/Blitz3D Programming/Mouse button helper function for y'all!

Ross C(Posted 2009) [#1]
Hey, I have written this a few times for my editor project, so i thought i'd post it here. Might help someone?

Basically, it makes it a touch easier to recognise what kind of mouse input your getting, instead of using mousehit and mousedown.

Just save this as a .bb file, and include it into your project, and call the function once every loop.

When you want your mouse input, simply check:

mouse_1_mode
mouse_2_mode
mouse_3_mode

Depending on what button you want to check of course. I have include const variables so you don't need to remember what the numbers mean. The variables will return:

0 - nothing pressed or hit
1 - the mouse was pressed in this loop
2 - the mouse is currently being held in
3 - the mouse was released from being held in
4 - the mouse was clicked
5 - the mouse was just held in this loop. Immeditately will change to mouse held, mode 2, if the mouse is still being held in.

You can adjust the mouse timers to give longer peroids before the "held" status gets set. This also affects the click time. If it's not a click, it's held basically. All 3 buttons get the exact same outputs.

Oh, and you might want to change the variable names, incase they clash with your project :)

Here is the include file:



Here is the code, with an example included. Run it, as it is.




wmaass(Posted 2009) [#2]
Just what I need, thanks!


Ross C(Posted 2009) [#3]
Glad someone gets a use from it :) Your welcome!


grantage(Posted 2009) [#4]
Wow this is great, thanks!


Ross C(Posted 2009) [#5]
Sorry, i'm afraid i've made a very small error in this include file. A typo of sorts, affecting the middle mouse held event. I've also added a mouse_just_held mode, for determining if the mouse has just offically been held down, ie. when the timer first recognises a mouse held event.

Anyway, here's the updated lib, with the fix and new mode, for anyone who is using this: