« Not-a-meme Recap | Main | Dolmere Webix #1 and #2 »

Typing Override Script and Laptop Keyboard Too (Part 4)

In this series of howto category blog entries we're creating a scripted laptop keyboard.
Part 1 | Part 2 | Part 3 | Part 4

LaptopSansMousepad.jpg
Prepped Laptop Primage

In the previous entry in this series we prepared our laptop object by removing the mouse and mousepad prims from the build. We now have a 4 prim wonder waiting to be fully transmogrified into a magical typing device.

LaptopDeleteHaloScript.jpg
Delete Halo Vendor Script

Click the contents tab in the editor window. Let's remove a leftover script from the Building Shelter vendor to cleanup a tiny bit. Delete the script "0HaloVendorEmbeddedScript" which was used by our in-world 3d vendor to rez and rotate objects for your browsing pleasure.

LaptopAddAnimationAndAttach.jpg
Add Animation and Attach

I have added an animation to the keyboard which was created by Roenik Newell. She calls it "speak-no-evil" and it moves the avatar's hands up to cover the avamouth. You can place any animation that you would like to use inside the laptop object but you will need to modify the script to change the name "speak-no-evil" to .

Once an animation has been added you can then attach your laptop to your avatar for positioning. Right click the laptop and choose "Take". This copies it back to your inventory. Now right click it in inventory and choose "Attach to" and in the submenu choose something like "Spine" or "Stomach". Spine or Stomach are probably some of the better attach points as they're less likely to rotate the keyboard when your avatar sits or otherwise stretches and rotates. Once you see the laptop show up on your person you can get started on aligning it to the proper location.

LaptopAdjustPosition.jpg
Adjust Laptop Position

Any attachment that allows modifications can be positioned on or about your avatar's body. If the current location of your laptop does not work for you simply edit it as shown here and reposition it until it's right.

LaptopRealigned.jpg
Position the Laptop - Success

You'll know the laptop is in the right place when it sits in front of your avatar about where your hands would fall when typing. Note that in these pictures the laptop is already transparent because I had already placed the new script in it. When ordering this howto I chose to leave the "insert the new script" step for later so that you'd be better able to view the laptop's position while editing its placement on this step.

LaptopRenameNewScript.jpg
Add and Rename a New Script

Click the "New script..." button in order to create a new script file inside the object's root prim. The contents will then display a new file named "New Script". This is where we will place the modified keyboard override script. Rename it by right clicking and choosing "Rename" from the contextual menu and then type out "KeyboardOverride" to give it a nice precise name.

LaptopKeyboardOverrideScript.jpg
Paste in Script Contents

The moment we've been waiting for has arrived. Scroll down to the bottom of this page and copy the script to your pasteboard. Now go back to Second Life, open the KeyboardOverride.lsl file and replace its default contents with the pasted contents of your clipboard. Save the file and it should compile and save without error.

Note: You CAN modify the script in the object's contents both while it is attached to you or while it is rezzed on the floor near you.

LaptopAsksPermission.jpg
Permissions Requested

Once the script compiles successfully it will start to run.

First it will make the laptop invisible. There is code in the script that attempts to ensure that when the laptop is rezzed in-world it is visible at all times but when rezzed as an attachment on an avatar it's visible only when you're typing.

The second thing that you should notice is that a dialog menu will popup asking for permission to "Animate your avatar". It's asking for the ability to run the "speak-no-evil" animation file in the keyboard's contents and you want to click Yes.

LaptopTestingSuccess.jpg
Test Your Keyboard

Now the moment of truth. If you're not wearing the laptop at this time then change that - wear it. Type. Test. What do you observe?

LaptopTestingSuccess2.jpg
Test Some More

If all is well then while you're typing text into the chat field your avatar will cover its mouth and a keyboard will appear in front of you.

You may notice that the keyboard and animation are working for me in this last picture. You may also notice that tiny Dolmere on my shoulder also has a keyboard out and on display at the same time - using the script I posted earlier.

What if you type one of those horrible live show message headers?

/Try this

/0Try this too

//Try this as well

What happens? Why?


The Script Itself

Copy and paste this code into your KeyboardOverride.lsl script in the laptop object in order to complete the task at hand. Questions? Comments? Feel free to IM me in-world or leave a comment here on this blog entry.


/// @file KeyboardOverride.lsl
/// Max Case's Free Keyboard Script 1.0 04/18/2005
/// Modified and renamed to KeyboardOverride 1.1 08/13/2007
///
/// Put it in a keyboard prim, attach it to yourself (or not) and
/// watch as that prim magically appears whenever you type.
/// Feel free to reuse, etc, but please don't just resell this script.
/// That would be lame, since I am giving it to you for free.
/// Naturally, if you build something nice off of it, sell that.
///
/// Or make a nice texture you would like to sell with keyboard script,
/// that's ok. Just leave script open to all to see.
///
/// Feedback/Rates/Donations/Hate Mail always welcome. Don't be shy.
/// leave in the comments; they don't affect performance.
/// – Max
///
/// Code comments assume that the keyboard is saved into the contents
/// of a keyboard object of some sort -Dolmere
///
/// @author Max Case, 04/18/2005
/// @author Vershana Amarula, 05/26/2005
/// @author Dolmere Talamasca 08/13/2007
///
/// Change history
///
/// 05/26/2005-VA Tweaks, changed variable names, added comments
/// and constants
///
/// 08/13/2007-DT Renamed file, modified description, added more comments


///
/// Declaration section - define and initialize all needed variables
///

/// The name or UUID of the animation to play when your avatar is typing
// An animation named "speak-no-evil" made by Roenik Newell for me is supplied as an example AO override.
// Change it to the string name of an animation that you have copied into the prim where this script will reside.
string newTypingAnimation = "speak-no-evil";

/// Keeps track of who is holding the object.
key kOwner;

/// Keeps track of the last typing state detected.
integer iPrevState;

/// Opacity percentage that represents "completely transparent".
float TRANSPARENT = 0.0;

/// Time interval to wait between testing for typing activity.
float TYPING_CHECK_PERIOD = .2;

/// Value to represent the (initial) state of "not typing".
integer IS_NOT_TYPING = 0;

/// Value to represent the state of "not being held"
integer IS_NOT_HELD = -1;

// The key for the default typing animation that Linden Lab uses
key typingAnim = "c541c47f-e0c0-058b-ad1a-d6ae3a4584d9";
// The actual name of the typing animation is "type"
// For more details see http://secondlife.com/badgeo/wakka.php?wakka=ClientAssetKeys and http://secondlife.com/badgeo/wakka.php?wakka=animation

// Track whether or not we have animation permissions
integer gotPermission = FALSE;

/// Perform all necessary operations to prepare script for use here.
initialize()
{
// During initialization, store the current owner to verify
// against later. If the owner changes, we'll reinitialize.
kOwner = llGetOwner();

// Make the entire object as transparent as our settings allow
llSetLinkAlpha(LINK_SET, TRANSPARENT, ALL_SIDES);

/// Set up a timer to periodically check for typing activity.
llSetTimerEvent(TYPING_CHECK_PERIOD);

// Assume that the owner is NOT typing at the time we're initialized.
iPrevState = IS_NOT_TYPING;

// Request permission to animate the owner of the prim where this script is executing
// This call will be resolved in the run_time_permissions() function below
llRequestPermissions(llGetOwner(), PERMISSION_TRIGGER_ANIMATION);
}

/// All behaviors associated with the default state.
default
{
// Operations to perform when entering state "default"
state_entry()
{
// Checks to see if we have changed owner when the script starts
// and (re)initializes if so.
if(llGetOwner() != kOwner)
{
initialize();
}
}

attach(key id)
{
if(id)//tests if it is a valid key and not NULL_KEY
{
initialize();
}
}

// Operations to perform when "rezzing" (using) the object
on_rez(integer total_number)
{
// Checks for new owner when object is rezzed and (re)initializes
// if so.
if(llGetOwner() != kOwner)
{
initialize();
}
}

run_time_permissions(integer perm) {
if( perm == (PERMISSION_TRIGGER_ANIMATION) )
{
gotPermission = TRUE;
}
}

// Operations to perform when the time value set with llSetTimerEvent elapses
timer()
{
// Is someone holding me?
integer iAttached = llGetAttached();

if(iAttached == 0)
{
// Not attached, make myself visible so I can easily be found
// (if I haven't already)!
if(iPrevState != IS_NOT_HELD)
{
// Make the entire object visible
llSetLinkAlpha(LINK_SET, 1.0, ALL_SIDES);
iPrevState = IS_NOT_HELD;
}
return;
}

// Are we typing? Thanks to Strife for rewrite here, though I find
// this sort of condensed logic can be confusing for non-programmer
// type, But this is definitely more efficient. -max
integer iTypingState = llGetAgentInfo(kOwner) & AGENT_TYPING;

// Has status changed since last checked?
if (iPrevState != iTypingState)
{
iPrevState = iTypingState;
if (iTypingState == 0)
{
if (llListFindList(llGetAnimationList(kOwner), [newTypingAnimation]))
{
// Make the entire object to be as transparent as settings allow
llSetLinkAlpha(LINK_SET, TRANSPARENT, ALL_SIDES);
llStopAnimation(newTypingAnimation);
}
} else
{
if (llListFindList(llGetAnimationList(kOwner), [newTypingAnimation]))
{
// Make the entire object visible
llSetLinkAlpha(LINK_SET, 1.0, ALL_SIDES);
llStartAnimation(newTypingAnimation);
}
}
}
}
}

Comments

The not so secret part 5 has been posted.

Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)

Recent Comments

Melynn said: The purple/pink guitar is in small pieces now, so it's a toad-ily mute point anyway. :) That's even more amusing.…

Crap Mariner said: You know, it would be amusing to have the equivalent of a Turing Test to see if people could figure out if a stream of chat is actually from me or if it's from …

Dolmere Talamasca said: One might note that the JIRA bug now has 650 votes for it. Keep 'em coming people, it's easy to login and add your vote if you think something like this is need…

Dolmere Talamasca said: Interesting way of looking at it, Vint. I would think more PA than PS but unpaid labor is still unpaid labor.…

Dolmere Talamasca said: Instead of the typing animation use "UISndTyping" and clear the field to accomplish the closest thing to what I'm looking for (As noted by Jacek at Crap Mariner said: *shrug* Got time to hit the tower on Monday with Cyl and SUPRISE SPECIAL GUEST? Not sure which song... um... Rainbow Connection would be cool basstasstically…