Weird keycapturing behavior
|
|
Kage Seraph
I Dig Giant Mecha
Join date: 3 Nov 2004
Posts: 513
|
01-14-2006 09:41
The following script gives me odd results and I'm stumped. It the linden flight script totally stripped down to just capture and report control events. When control_right or control_left is triggered, press-release-press messages are sent, instead of the expected press only. none of the other keys do this. The behavior is the same regardless of if the events ar ORed together as below, or if they are handled in separate IF statements. // control flags that we set later integer gControls = 0;
default { state_entry() { gControls = CONTROL_RIGHT | CONTROL_LEFT | CONTROL_ROT_RIGHT | CONTROL_ROT_LEFT | CONTROL_DOWN | CONTROL_UP | CONTROL_FWD | CONTROL_BACK; llRequestPermissions(llGetOwner(), PERMISSION_TRIGGER_ANIMATION | PERMISSION_TAKE_CONTROLS); }
changed(integer change) { if (change & CHANGED_LINK) { key agent = llAvatarOnSitTarget(); if (agent) { if (agent != llGetOwner()) { // only the owner can use this vehicle llSay(0, "You aren't the owner"); llUnSit(agent); llPushObject(agent, <0,0,10>, ZERO_VECTOR, FALSE); } else {//fire up all systems llRequestPermissions(agent, PERMISSION_TRIGGER_ANIMATION | PERMISSION_TAKE_CONTROLS); } } else { // stop the motors llReleaseControls(); llStopAnimation("motorcycle_sit"); } }
}
run_time_permissions(integer perm) { if (perm) { llStartAnimation("motorcycle_sit"); llTakeControls(gControls, TRUE, FALSE); } }
control(key id, integer level, integer edge) { if(level) {//this block captures the keypresses if(level & edge & CONTROL_FWD) { llOwnerSay("fwd press"); } else if(level & edge & CONTROL_BACK) { llOwnerSay("back press"); } else if((level & edge & CONTROL_ROT_LEFT) | (level & edge & CONTROL_LEFT)) { llOwnerSay("left press"); } else if((level & edge & CONTROL_ROT_RIGHT) | (level & edge & CONTROL_RIGHT)) { llOwnerSay("right press"); } else if(level & edge & CONTROL_UP) { llOwnerSay("up press"); } else if(level & edge & CONTROL_DOWN) { llOwnerSay("down press"); } } if(~level) {//this block captures the key releases if(~level & edge & CONTROL_FWD) { llOwnerSay("fwd release"); } else if(~level & edge & CONTROL_BACK) { llOwnerSay("back release"); } else if((~level & edge & CONTROL_ROT_LEFT) | (~level & edge & CONTROL_LEFT)) { llOwnerSay("left release"); } else if((~level & edge & CONTROL_ROT_RIGHT) | (~level & edge & CONTROL_RIGHT)) { llOwnerSay("right release"); } else if(~level & edge & CONTROL_UP) { llOwnerSay("up release"); } else if(~level & edge & CONTROL_DOWN) { llOwnerSay("down release"); } } } }
|
|
Kairen Overdrive
Registered User
Join date: 12 Jul 2005
Posts: 38
|
01-14-2006 10:53
oh , thats very normal. Read about it first before posting: http://secondlife.com/badgeo/wakka.php?wakka=control The control event activates all the time some key is pressed/released/changed etc. You can get a piece of code to be played over 100 times by just holding a key for a few seconds or just once between press and release. Sounds a bit confusing maybe. But its a pretty simple concept.
|
|
Kage Seraph
I Dig Giant Mecha
Join date: 3 Nov 2004
Posts: 513
|
01-14-2006 12:15
My apologies for being inarticulate in trying to express my original question. =) Spent all morning on that wakka page before posting. A bit more explanation is in order. The script is set up to OwnerSay the action performed on the keyboard, so pressing and releasing the up arrow, for example, generates something like the following chat log: From: someone Grabber: forward pressed Grabber: forward released
However, with the CONTROL_RIGHT or CONTROL_LEFT events, the following log is produced (from a single press and release): From: someone Grabber: right pressed Grabber: right released Grabber: right pressed Grabber: right released
The first three lines are generated on the keypress, the last on release. It would appear, then, that the keypress only for CONTROL_RIGHT and CONTROL_LEFT generate three control events, not one each as expected. CONTROL_ROT_LEFT and RIGHT work as expected, generating only one control event per press, as do pgup, pgdn. What am I missing here? The control handlers are set up to only catch presses and release, so there should be no flood of control events signaling keyDown; only when edges evaluates to TRUE.
|
|
Zepp Zaftig
Unregistered Abuser
Join date: 20 Mar 2005
Posts: 470
|
01-14-2006 12:32
I've noticed this too. It seems to only happen when you're in mouselook though, so you can do do some stuff with if(llGetAgentInfo(llGetOwner()) & AGENT_MOUSELOOK) to avoid it.
|
|
Kage Seraph
I Dig Giant Mecha
Join date: 3 Nov 2004
Posts: 513
|
01-14-2006 12:40
Funky. Thanks, Zepp!
|
|
Seagel Neville
Far East User
Join date: 2 Jan 2005
Posts: 1,476
|
01-14-2006 20:27
From: Kage Seraph The first three lines are generated on the keypress, the last on release. It would appear, then, that the keypress only for CONTROL_RIGHT and CONTROL_LEFT generate three control events, not one each as expected. CONTROL_ROT_LEFT and RIGHT work as expected, generating only one control event per press, as do pgup, pgdn.
What am I missing here?
The control handlers are set up to only catch presses and release, so there should be no flood of control events signaling keyDown; only when edges evaluates to TRUE. I'm sorry, but I don't still understand. I thought it was quite natural to work like above. Pressing Left and Right arrow keys are expected to generate two actions. First is turn Left or Right, and then go Left or Right. If you'd like to avoid turning, you should press Shift + Left or Right key to control. Or to avoid letting it say while turning, what about just not writing llOwnerSay under "else if((level & edge & CONTROL_ROT_LEFT))" statement?
_____________________
 Seagel Neville 
|
|
Kage Seraph
I Dig Giant Mecha
Join date: 3 Nov 2004
Posts: 513
|
01-14-2006 20:56
From: Seagel Neville I'm sorry, but I don't still understand. I thought it was quite natural to work like above. Pressing Left and Right arrow keys are expected to generate two actions. First is turn Left or Right, and then go Left or Right. If you'd like to avoid turning, you should press Shift + Left or Right key to control. Or to avoid letting it say while turning, what about just not writing llOwnerSay under "else if((level & edge & CONTROL_ROT_LEFT))" statement? Hi, Seagel! The issue that stymies me so far is that the Rot_left versus the left keypresses generate a different number of events, when as far as I know they should each produce the same number. The specific outcome of ownersay output is pretty much irrelevant and only a convenient form of feedback. The eventual application of this is to see how easily a control script can communicate with multiple vehicle propulsion scripts via linkmessages.
|
|
Seagel Neville
Far East User
Join date: 2 Jan 2005
Posts: 1,476
|
01-14-2006 21:54
 Sorry, I've got what you were saying after trying actually your script. And I've also understood Zepp's advice. I always forget that I must do it actually without just thinking in my mind. 
_____________________
 Seagel Neville 
|
|
Kage Seraph
I Dig Giant Mecha
Join date: 3 Nov 2004
Posts: 513
|
01-15-2006 05:50
It is all good. =) I'm honored you took the time to compile it inworld.
|
|
Gerami Fizz
That Guy
Join date: 15 Jun 2005
Posts: 88
|
01-17-2006 12:23
Kage, are you still experiencing this problem? I just ran into it myself while working on a project... no solution yet. It happens for me even out of mouselook.
|
|
Kage Seraph
I Dig Giant Mecha
Join date: 3 Nov 2004
Posts: 513
|
01-17-2006 12:33
Yo! I am still experiencing it in that I have not had time to address it yet. =) Try folks' suggestions above?
|
|
Kage Seraph
I Dig Giant Mecha
Join date: 3 Nov 2004
Posts: 513
|
...
01-20-2006 07:17
Well that's MY KIND OF BUGFIXING!
I just copied the script from the forum and dumped it into a fresh object, and now it works as expected. Wieeeeeerd.
|
|
Oasis Perun
Registered User
Join date: 2 Oct 2005
Posts: 128
|
01-20-2006 10:43
just curious yal... but does your keyboard "repeat" setting have anything to do with the control press repeating...maybe?
|
|
Kage Seraph
I Dig Giant Mecha
Join date: 3 Nov 2004
Posts: 513
|
01-20-2006 11:00
Not as far as I can tell. One would expect the repeat to either work on both control_rot_right and control_right, but it only does on control_right (or did--works fine now).
|
|
Seagel Neville
Far East User
Join date: 2 Jan 2005
Posts: 1,476
|
01-21-2006 11:08
 But I did the exact same thing with you! Did we chose the wrong day? 
_____________________
 Seagel Neville 
|
|
Kage Seraph
I Dig Giant Mecha
Join date: 3 Nov 2004
Posts: 513
|
01-21-2006 18:59
/me makes weak attempt at excuse based on hamsters treadmilling the asset server. *shrug* 
|
|
Gerami Fizz
That Guy
Join date: 15 Jun 2005
Posts: 88
|
02-08-2006 15:43
Well, I've implemented the hackiest solution ever, but so far it works for me: Add one line of code at the end of your CONTROL_LEFT and CONTROL_RIGHT events: llSleep(0.1); Short enough not to really affect control, but long enough to prevent repeats. I did a little visual experimentation with the movement controls. Check out the responsiveness of turning or moving forward, then try walking sideways from a standstill. With most of the controls you move immediately. When you try to walk left or right, you take a step, hesitate, then keep walking. Repeated keypress behavior? I think so. Hope this helps.
|
|
Rickard Roentgen
Renaissance Punk
Join date: 4 Apr 2004
Posts: 1,869
|
02-08-2006 17:16
interesting, I don't think I've ever tested this but it would explain a stutter I've seen in one of my vehicles  . I notice you're checking for both rot_ and non rot_ values and someone else said it only happened in mouselook. Is it perhaps triggering rot_left releasing then triggering _left?
|
|
Lex Neva
wears dorky glasses
Join date: 27 Nov 2004
Posts: 1,361
|
02-09-2006 09:14
From: Rickard Roentgen interesting, I don't think I've ever tested this but it would explain a stutter I've seen in one of my vehicles  . I notice you're checking for both rot_ and non rot_ values and someone else said it only happened in mouselook. Is it perhaps triggering rot_left releasing then triggering _left? You can trigger left and right events by holding down shift to strafe, while not in mouselook. I wonder if this triggers the jitter? The jittering I've seen involves 3 events in rapid succession with the same control.
|
|
Gerami Fizz
That Guy
Join date: 15 Jun 2005
Posts: 88
|
02-09-2006 09:49
As near as I can tell, the "jitter" I see (based on debugging code in a script I was writing) is a press-release-press. So yes, three events. When I do this I am in fact using the shift key in the normal view, and from a dead stop (no other controls in use).
|
|
Archanox Underthorn
Registered User
Join date: 20 May 2003
Posts: 168
|
02-09-2006 21:07
I've experienced another instance where this double keypress happens. It seems if you hold forward or back and then hit one of the directions it also happens. Just something to look out for, I had to implement my code so the left and right actions wouldnt fire if fwd or back was being pressed because of this.
_____________________
Archatek
Home to some of the highest quality katanas and other blades available in SL. Co-creator of the Samurai Island Combat System, one of the best melee combat systems available, come check it out!
___________________
|