January 17, 2017

Capturing Input

Capturing mouse clicks is pretty easy in Etoys. There are several mouse events that can selected in the script editor status menu. The script will run whenever that mouse action is performed on the associated object. The mouse enter dragging and mouse leave dragging events seem to work best when you are dragging another object onto your object. Note that you may only be able to move objects with the move icon handle when one of their scripts is waiting for a mouse event. This example project someMouseEvents.003.pr can be downloaded from my GitHub repository. Save to your Etoys directory and open in Etoys.

You can also add mouse over balloon help text to objects through the menu options halo icon.

Script Activation Button ImageGet buttons to run your scripts in their script editor menu options. The buttons have a built in effect but you can customize their looks with their halo icons. If you want to create customized effects then use the button object in the object catalogue scripting category. Buttons have an icon in their halo to quickly bring up the script they are associated with.

All objects have an input category reporting keystrokes so keyboard input can be captured by scripts inside any object. Values are of type string so can only be tested for equality and cannot be assigned to any other variable type than string. The spacebar registers as a blank character. Non alphanumeric keys show their value between angle brackets,  for example,  the up arrow key looks like this <up>. The control key reports as <cmd- > and the alt key reports as <ctrl-> so be careful using key combinations other than shift as they can activate Squeak commands. The Enhanced Text object in the object catalogue connectors category can be set to respond to the enter key or the mouse cursor leaving it. Scripts created in Enhanced Text objects can have status set to acceptedTextContents meaning the script will run either when the enter key is pressed or the object loses mouse focus depending on what's been set.

The just for fun category in the object catalogue has a Key Press object. This object has an individual keyboard key assigned to it and reports true whenever that key is pressed and how long it has been pressed for.  This is pretty useful for controls that accelerate for example. Scripts have no special status so other than when using the Enhanced Text object, scripts that capture keyboard input must be set to ticking.

If you want to restrict your user to entering numerical input, then you are best to use a watcher for the variable or property capturing the input or use a Slider object which can be found in the supplies flap or the basic category in the object catalogue. You can build nice forms by using simple watchers and labelling them however you want with adjacent Text objects.

Sliders have extra tiles in the viewer category slider. Capture Slider values either with a ticking script in the Slider or a script inside the Slider's Rectangle object set to Mouse Still Down status.

Some objects in the Multimedia category accept input from the pc microphone jack. The Sound Recorder and World Stethoscope work well with audio. The OLPC has a page on adapting a 3.5mm jack to connect other types of sensors but I have never tried this. The microphone jack is not a typical method of connecting sensors and this page is specifically about the XO laptop.

There is a Joystick object in the supplies flap. I have had success connecting an XBox 360 controller in Windows but it can also be used just with the mouse.



Last Updated.