Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

detecting the SHIFT Key

Ryder Spearmann
Early Adopter
Join date: 1 May 2006
Posts: 216
05-06-2007 10:35
Hi All,

have seen some objects that somehow register the SHIFT key in their scripts... I think I have anyway... sadly I can't recall where I saw this! (grrr)

Anyone know how?

Thx :)

-Ryder-
Talarus Luan
Ancient Archaean Dragon
Join date: 18 Mar 2006
Posts: 4,831
05-06-2007 10:41
No, never heard of that. I think you might be mistaken on that one.

The keys which can be detected are detailed under the llTakeControls function in the Wiki.
Ryder Spearmann
Early Adopter
Join date: 1 May 2006
Posts: 216
05-06-2007 10:54
I may indeed be wrong...

Q: Why in BLAZES, does LL limit the key controls so much? It seems so arbitrary.

Why not add a few. Space bar? RMB? I dunno... something.

"Give me a bone, people!"
RobbyRacoon Olmstead
Red warrior is hungry!
Join date: 20 Sep 2006
Posts: 1,821
05-06-2007 10:59
I don't believe it's possible to detect the shift key in LSL. I've railed against this for months, but even looking at the open source viewer code I don't see any way to enable that since the control events are all server-side in your LSL script and the server simply doesn't process any keys not mentioned in the llTakeControls documentation that Talarus mentioned above.


.
_____________________
Ryder Spearmann
Early Adopter
Join date: 1 May 2006
Posts: 216
05-06-2007 11:17
Then I guess we are stuck with combinations of keys... (W+S) etc.

Does someone have a code snippit of how to detect key combos?
RobbyRacoon Olmstead
Red warrior is hungry!
Join date: 20 Sep 2006
Posts: 1,821
05-06-2007 11:37
From: Ryder Spearmann
Then I guess we are stuck with combinations of keys... (W+S) etc.

Does someone have a code snippit of how to detect key combos?


Detecting key combos is rather easy, since they key constants are bit flags. You might have some problems with timing, so you might have to explicitly look for both keys being pressed and not just one of them, or you might have an issue where one of the "chord" keys are pressed just slightly before the other, though.

I am assuming that you've read the quoted Wiki page, but if you look at the ExampleControls script, you can see that they are already kind of checking for combinations.

Here's an example that checks for the mouse, jump, and crouch buttons simulaneously:

CODE

// example_controls.lsl // ready jack // 21 jan 2006 // v1.0

// Put this in an attachment. When you put the script in or make
// a change, you have to re-attach the object to activate the controls.

default
{
attach(key who)
{
if (who == NULL_KEY) {
// detached
if (llGetPermissions() & PERMISSION_TAKE_CONTROLS) {
llReleaseControls();
}
} else {
llRequestPermissions(who, PERMISSION_TAKE_CONTROLS);
}
}

run_time_permissions(integer perms)
{
integer desired_controls =
CONTROL_FWD |
CONTROL_BACK |
CONTROL_LEFT |
CONTROL_RIGHT |
CONTROL_ROT_LEFT |
CONTROL_ROT_RIGHT |
CONTROL_UP |
CONTROL_DOWN |
CONTROL_LBUTTON |
CONTROL_ML_LBUTTON
;

if (perms & PERMISSION_TAKE_CONTROLS) {
llTakeControls(desired_controls, TRUE, TRUE);
}
}

control(key id, integer down, integer new)
{
integer pressed = down & new;
integer held = down & ~new;
integer released = ~down & new;

// Notice that held is used instead of pressed, to
// allow a little flexibility in detecting the chord
// while allowing one key to be pressed just slightly
// ahead of others. In other words, do nothing until
// *all* of these keys are pressed.
if (held & (CONTROL_FWD | CONTROL_UP | CONTROL_DOWN)) llOwnerSay("chord complete");

}
}


This has not been tested, so lemme know if it doesn't work, but I'm pretty sure it's going to :)


.
_____________________
Ryder Spearmann
Early Adopter
Join date: 1 May 2006
Posts: 216
05-06-2007 12:22
Mmmm nope... does not work.

I think it is close... but the CONTROL_ML_LBUTTON does not work in the combo.

CONTROL_ML_LBUTTON returns a strange value... 1073741824

?????
-Ryder-
Talarus Luan
Ancient Archaean Dragon
Join date: 18 Mar 2006
Posts: 4,831
05-06-2007 12:59
Ummm. What part of "bit flags" is not clear?

CONTROL_ML_LBUTTON is the bit flag 0x40000000, which is the same as decimal 1073741824.
RobbyRacoon Olmstead
Red warrior is hungry!
Join date: 20 Sep 2006
Posts: 1,821
05-06-2007 13:00
From: Ryder Spearmann
Mmmm nope... does not work.

I think it is close... but the CONTROL_ML_LBUTTON does not work in the combo.

CONTROL_ML_LBUTTON returns a strange value... 1073741824

?????
-Ryder-


Oh... CONTROL_ML_LBUTTON is the mouse button in MouseLook mode. The other one, CONTROL_LBUTTON, is likely the one you want.


.
_____________________
Ryder Spearmann
Early Adopter
Join date: 1 May 2006
Posts: 216
05-06-2007 13:05
THx guys...

I am using it in mouselook, so ML is the one I want.

But the combos are not working... they pass the IF condition by themselves...

I made these changes...

CODE

control(key id, integer down, integer new)
{
integer pressed = down & new;
integer held = down & ~new;
integer released = ~down & new;
integer dn = FALSE;
integer mlb = FALSE;

if (held & CONTROL_DOWN) dn = TRUE;
if (pressed & CONTROL_ML_LBUTTON) mlb = TRUE;
if (dn & mlb)
{
llSay(0,"it works!");
}
}
Kenn Nilsson
AeonVox
Join date: 24 May 2005
Posts: 897
05-06-2007 14:36
Changing your code just SLIGHTLY to make it a bit more efficient...

From: Ryder Spearmann

CODE

control(key id, integer down, integer new)
{
integer pressed = down & new;
integer held = down & ~new;
integer released = ~down & new;
integer dn = FALSE;
integer mlb = FALSE;

if (held & CONTROL_DOWN)
{
if (pressed & CONTROL_ML_LBUTTON)
{
llSay(0,"it works!");
}
}
_____________________
--AeonVox--

Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms chasing ghosts, eating magic pills, and listening to repetitive, addictive, electronic music.
Ryder Spearmann
Early Adopter
Join date: 1 May 2006
Posts: 216
Apparently there IS a way to use the shift Key!
06-28-2007 15:09
Hi all...

I thought I was nuts when I recalled seeing someone use the Shift key as part of user input... and I have now seen it again.

Twice.

One is part of the golfing interface system in Hollywood, it uses a shift left mouse button combination.

Another is a bar stool... where a shift click causes a change in the seating position on the stool.

Can anyone else confirm or shed light on this "shift" key business?

Thanks in advance.

-Ryder-
Alicia Mounier
Registered User
Join date: 17 Oct 2005
Posts: 78
06-28-2007 15:55
The only thing is see where the shift key comes into play is where CONTROL_LEFT and CONTROL_RIGHT are used. while out of mouselook and hitting CONTROL_LEFT A/left arrow key you spin where as hitting CONTROL_LEFT and shift makes you walk left. while in mouselook doing the same key presses produces the same results where as you'll strafe left even if you held down the shift key while pressing A/left arrow key, CONTROL_LEFT. Now with the golf game i would have to play to see but from what it sounds it uses the left mouse button in conjunction with shift A/left arrow key to produce a certain control or outcome for a control in the game. As far as LSL actualy decting the shift key alone seems to be limited to just the above mentioned keys. Kinda like llGetAgentInfo where it will detect and return AGENT_CROUCHING but not AGENT_CROUCHWALKING. Things they seemed to forget to add while making the codes, or left out for some unknown reason.
Qie Niangao
Coin-operated
Join date: 24 May 2006
Posts: 7,138
06-29-2007 02:29
From: Ryder Spearmann
One is part of the golfing interface system in Hollywood, it uses a shift left mouse button combination.
So I went to Hollywood :cool: and checked out the golfing instructions. The Shift key appears in: "Select a club by clicking on the appropriate button. Then use the left and right arrow keys to aim your shot. Shift-arrows will move the address arrow faster." So this particular use of the Shift key would effect CONTROL_LEFT rather than CONTROL_ROT_LEFT, for example, as Alicia describes, but wouldn't involve a mouseclick at all.

The only other place I can think of where the Shift key does anything a script could detect does involve the mouse: the Control-Shift-Drag operation on movable objects, which will cause them to rotate rather than translate as does Control-Drag. Mischief could be made, then, with llDetectedGrab() in the touch() event.
Ryder Spearmann
Early Adopter
Join date: 1 May 2006
Posts: 216
07-03-2007 07:46
From: Qie Niangao
So I went to Hollywood :cool: and checked out the golfing instructions. The Shift key appears in: "Select a club by clicking on the appropriate button. Then use the left and right arrow keys to aim your shot. Shift-arrows will move the address arrow faster." So this particular use of the Shift key would effect CONTROL_LEFT rather than CONTROL_ROT_LEFT, for example, as Alicia describes, but wouldn't involve a mouseclick at all.


Yes, my bad... it is shift + arrow keys... The bar stool that uses it changes poses based on this... but still, an interesting addition of shift key function