Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Code Snippets / Function for detecting mouse/key states

Author
Message
Zergei
19
Years of Service
User Offline
Joined: 9th Feb 2005
Location: Everywhere
Posted: 28th Aug 2006 21:21
I've made this function that will tell you whether the mouse or a key as been pressed, double pressed, press and hold or double press and hold. As stated above it works for both keyboard and mouse, and probably would work for a joypad.

I'd like some comments of it, and if there is another/better way of achiving this.

Here goes the code:




A quick review of what each parameter does:
- "b" you tell where to save it within the array btm(n). This is for keys only, for mouse you put 0 , and it will save the 3 mouse buttoms states on b=1, b=2 and b=3 , so if your to use both mouse and keys, save your keys begining 4.
- "m" wich key to read (ex: keystate(2)). If b=0 so to read mouse input, you state whether 1(left) , 2(right) or 3(center) buttom.
- "t" state the time taken between click/double-click recognition.
- "flag_timer" this one is tricky. A value of 0 states that you want to recognize a buttom once the timer has ended, a value of 1 will activate the state of the mouse either the timer has ended or not. This is preaty much like shooting a weapon once the buttom has gone from unpressed to a pressed state (flag_timer=1) or from a pressed state to a unpressed state (flag_timer=0).

Please do comment, and thanks for your time.

Further on my stuff at...
Zergei
19
Years of Service
User Offline
Joined: 9th Feb 2005
Location: Everywhere
Posted: 31st Aug 2006 16:54
Looks like it's not as usefull as i thought...

Further on my stuff at...
Sixty Squares
18
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 31st Aug 2006 20:35
I'm confused on the FLAG_Timer thing. The rest sounds good though!

Zergei
19
Years of Service
User Offline
Joined: 9th Feb 2005
Location: Everywhere
Posted: 1st Sep 2006 04:25 Edited at: 1st Sep 2006 04:59
Yeah, at first it looks weird. I'll try to explain it as best as i can.

With flag_timer=0 : A "Click" is achieved once "t" reachs 0, so if you set "t" a high value and you click the mouse, it won't return a "Click" until "t" has reached 0, thus it may feel weird. Just try it.

With flag_timer=1 : Same as before, but once the buttom has been released it will return a "Click" state, wherther or not your after a "DoubleClick" status.

Further on my stuff at...
Hoozer
18
Years of Service
User Offline
Joined: 8th Sep 2006
Location: Bremerhaven (Germany)
Posted: 28th Sep 2006 22:54
I will give it a try! It seems like the things I was looking for the whole time! (Just started with DB-Pro and thought there was something like "pressed", "released" etc, but I was wrong!)

I hope I can set it up in my game!


Thanks a lot for your work!

Hoozer

Login to post a reply

Server time is: 2024-11-23 03:39:16
Your offset time is: 2024-11-23 03:39:16