How do I detect a keyboard doubletap?
|
|
BETLOG Hax
Geek
Join date: 22 May 2007
Posts: 91
|
05-25-2007 15:45
How do I detect a keyboard doubletap? I would like to detect when the user double taps a keyboard key so I can add a secondary function. eg: double tap walk to activate run etc (i actually plan to use it with flying, but walk/run is a nice clear example)
|
|
Aaron Edelweiss
Registered User
Join date: 16 Nov 2006
Posts: 115
|
05-25-2007 16:16
I've noticed recently that the control event seems to be broken for some people. It'll fire twice, once with a control pressed and once not pressed, and repeat in that pulsing fashion. You might be out of luck. However, you can try this. float last_tap; float double_tap_time = 0.5; // seconds default { // take controls, etc, so forth... control(key id, integer level, integer edge) { if (edge & CONTROL_FORWARD) { if (llGetTime() - last_tap < double_tap_time) { // double tap detected, do stuff } else { last_tap = llGetTime(); } } } }
|
|
Aaron Edelweiss
Registered User
Join date: 16 Nov 2006
Posts: 115
|
05-25-2007 16:19
I can't seem to get the php tags to work, maybe they no longer exist or don't work in this forum? anyway, there should be indents, but that will work I think.
|
|
BETLOG Hax
Geek
Join date: 22 May 2007
Posts: 91
|
05-25-2007 17:07
Thanks, I'll try it now.
Yes, I am noticing a lot of double touches happening on a touch activated texture cycling prim i was just tinkering with... doesn't seem to happen with rightclick-"touch" though, just left click.
Also, yes, iirc I read somewhere that BB formatting has been disabled.
Note: minor correction to your code = CONTROL_FWD not CONTROL_FORWARD
|
|
Talarus Luan
Ancient Archaean Dragon
Join date: 18 Mar 2006
Posts: 4,831
|
05-25-2007 17:48
There's really no good way to determine real-time keypresses. Everything between the client and the server is polluted by lag, so while a routine like the above *might* work, it will never work consistently.
If that is OK with you application, then cool. Otherwise, you will have to re-write it to use some other form of input control to perform its function.
|
|
BETLOG Hax
Geek
Join date: 22 May 2007
Posts: 91
|
05-25-2007 18:53
Well I tried it out and couldn't get it to work in any form, I suspected this related to the lag as you suggest, but even with a large doublepress time window (0.75s) I still couldn;t get it to work in the context i tried using it. I suspect that this is because despite not being a total novice at coding in general, i am completely self taught, and a total newb at LSL (started a week ago). So it's probably some stupid oversight thats making it fail.
Here's what i was trying to do: Modify the following flight code so that instead of typing 'fly' or 'speed' to activate turbo mode, I would instead simply doublepress a direction key, and it would remain in turbo mode for as long as i held the doublepressed key down. Auto returning to normal mode when any direction was released.
Rather than subject us all to the visual horrors of untabbed code on this forum, here is the code source: http://virtualunderworld.net/arianeb/enhancedfly.txt and it's description/instructions: http://virtualunderworld.net/arianeb/secondlife.htm
|
|
Talarus Luan
Ancient Archaean Dragon
Join date: 18 Mar 2006
Posts: 4,831
|
05-26-2007 09:34
Well, it's not any lack of programming skill on your part, it's simply that such kind of input detection doesn't exist in SL at all.
Maybe try a HUD? or maybe use mouselook and CONTROL_ML_LBUTTON to activate turbo mode?
|
|
BETLOG Hax
Geek
Join date: 22 May 2007
Posts: 91
|
05-26-2007 10:06
Ok, thanks for the help. I already use a simple HUD for the 250m+ thruster I use at the moment, but I was hoping for as more elegant solution. I'll probably persist with the doubletap code at some later time, and try some different variables.. because that really is the preferred solution.
|