Sticking keyboard Bug


28 posts   Page 1 of 2   1, 2
by simplesi » Wed Sep 19, 2012 10:59 pm
@proxima mentioned a little bug they'd found in a PM so I had a look into it and this little script shows the problem
https://dl.dropbox.com/s/fxbqmrxt4pw60nd/keybug.sb

Press up -scratch moves up - press right - scratch moves right - OK so far :0

press both together and scratch keeps on doing the first keypress until you hit the first key again :(

Doesn't seem to happen if you just use a simple key pressed orange block but a lot of games use the key x pressed version in a loop

Simon
Seeking help with Scratch and I/O stuff for Primary age children
http://cymplecy.wordpress.com/ @cymplecy on twitter
Posts: 2112
Joined: Fri Feb 24, 2012 6:19 pm
Location: Euxton, Lancashire, UK
by proxima » Thu Sep 27, 2012 10:22 am
simplesi - thanks for reporting that, sorry I didn't get around to it sooner.

Just having my second play with my Pi (sorry, my son's Pi - got to remember that....) and created a test script to demo the problem, but looks like you've already reported it.

A bit more information: As I think you've already said, this is a problem specific to Scratch - so in other words it's not a problem with my keyboard or power supply (which can cause keyboard problems), or the Pi itself. No other Pi application seems to display this problem.

But on the other hand, it's specific to Scratch *on the Pi* - so the same script running in Scratch on Windows (even with the same keyboard) does NOT have this problem.

I hope that extra info might help. I'll keep an eye for any updates, as this is going to make some games we write (and the 'marbleracer' example) fairly unplayable.
Posts: 30
Joined: Tue Sep 18, 2012 3:16 pm
by proxima » Sun Sep 30, 2012 9:40 am
Just confirmed: The problem still occurs in Scratch running on the latest (2012-09-18) distribution.

Tom
Posts: 30
Joined: Tue Sep 18, 2012 3:16 pm
by simplesi » Sat Oct 06, 2012 7:41 am
So following on from ked showing us how to set up a separate Scratch VM it seems the sticky keys bug goes away if Scratch is launched in a different manner

e.g put this code into a file called test_scratch.sh
Code: Select all
#!/usr/bin/env bash
/usr/lib/squeak/4.4.7-2357/squeakvm \
-encoding UTF-8 \
-vm-display-x11 -xshm \
-plugins /usr/lib/scratch/plugins/:/usr/lib/squeak/4.4.7-2357/ \
-vm-sound-alsa \
/usr/share/scratch/Scratch.image

and then
Code: Select all
chmod u+x test_scratch.sh


and then ./test_scratch.sh

then you'll find that the sticky keys problem has gone away.

So we need to find out what the difference between this method of launching Scratch and how the RPi normally does it.

Simon
Seeking help with Scratch and I/O stuff for Primary age children
http://cymplecy.wordpress.com/ @cymplecy on twitter
Posts: 2112
Joined: Fri Feb 24, 2012 6:19 pm
Location: Euxton, Lancashire, UK
by dmurday » Tue Oct 09, 2012 3:30 pm
Slowly the bugs are being ironed out. Will be nice to see an official fix to all these problems but at least in the interim scratch it becoming pretty reliable on the pi.

Are you going to add this to the script that launches scratch and the gpio handler?
Posts: 14
Joined: Sat Aug 25, 2012 10:35 am
by simplesi » Tue Oct 09, 2012 4:18 pm
Are you going to add this to the script that launches scratch and the gpio handler?


I'm hoping someone else works out exactly what the issue is but if not then I might have to do it but I really want an official fixed Scratch and not have to supply my variation on it :)

Simon
Seeking help with Scratch and I/O stuff for Primary age children
http://cymplecy.wordpress.com/ @cymplecy on twitter
Posts: 2112
Joined: Fri Feb 24, 2012 6:19 pm
Location: Euxton, Lancashire, UK
by proxima » Tue Oct 09, 2012 4:36 pm
I'm hoping to have a look at the difference between the two startup scripts later tonight (will make a change after 10 hours of solid debugging in my day-job :? ).
Posts: 30
Joined: Tue Sep 18, 2012 3:16 pm
by robochrish » Tue Oct 09, 2012 9:47 pm
I am having this problem as well.
I only got my Pi yesterday so I'm really new with it.
I tried to do the fix that you suggested with the test_scratch.sh file, but I could only get as far as creating that file. I didnt know what to do after that.

Could you possibly break it down for me please?

Thanks
Posts: 3
Joined: Tue Oct 09, 2012 9:45 pm
by simplesi » Wed Oct 10, 2012 6:46 am
Did you save your file as test_scratch.sh?

If so then jsut open up LX Terminal and do
Code: Select all
chmod u+x test_scratch.sh


This makes the test_scratch.sh file executable

then to run it you just type

Code: Select all
./test_scratch.sh


At the moment, this just seems to cure the problem but since the code that I think is normally used to run Scratch (/usr/bin/x11/scratch) looks like this
Code: Select all
#!/bin/sh
# File:            scratch
# Description:     Script to start the Squeak VM binary with the scratch image
# Original Author: Bert Freudenberg
# Adapted by:      Miriam Ruiz

VM_VERSION=`find /usr/lib/squeak/ -name "squeakvm" -type f|cut -f5 -d"/"`
SQ_DIR=/usr/lib/squeak/$VM_VERSION
VM="$SQ_DIR/squeakvm"
VMOPTIONS="-encoding UTF-8 -vm-display-x11 -xshm -plugins /usr/lib/scratch/plugins/:$SQ_DIR/"
IMAGE="/usr/share/scratch/Scratch.image"
IMOPTIONS=""
DOCUMENT=""
WRAPPER=""

#set to 1 to work around OLPC bug #8008
export SQUEAK_FAKEBIGCURSOR=0

# default directories (used if not running as Sugar activity)
[ -z "$SQUEAK_SECUREDIR" ] && export SQUEAK_SECUREDIR="$HOME/.scratch/private"
[ -z "$SQUEAK_USERDIR" ] && export SQUEAK_USERDIR="$HOME/Scratch"

[ ! -d "$SQUEAK_SECUREDIR" ] && mkdir -p "$SQUEAK_SECUREDIR" && chmod 700 "$SQUEAK_SECUREDIR"
[ ! -d "$SQUEAK_USERDIR" ] && mkdir -p "$SQUEAK_USERDIR"

[ ! -d "$HOME/Documents" ] && mkdir -p "$HOME/Documents"

usage()
{
    echo "Usage: scratch [--param value] [-vmopt value] [arg value]"
    echo "       where --param is --vm, --image, or --document;"
    echo "       -vmopt is an option passed to the Squeak VM;"
    echo "       and args are passed to the Squeak image."
}

if [ $# -eq 1 ] ; then
   case "$1" in
       /*) DOCUMENT="$1"
      ;;
       *) DOCUMENT="$PWD/$1"
      ;;
   esac
   shift
else
    while [ -n "$1" ] ; do
   if [ -z "$2" ] ; then
           usage
      exit -1
   fi
   case "$1" in
           --help)
         usage
          exit
         ;;
           --document)
         case "$2" in
             /*) DOCUMENT="$2"
            ;;
             *) DOCUMENT="$PWD/$2"
            ;;
         esac
          shift
         ;;
           --image)
         case "$2" in
             /*) IMAGE="$2"
            ;;
             *) IMAGE="$PWD/$2"
            ;;
         esac
          shift
         ;;
           --vm)
         case "$2" in
             /*) VM="$2"
            ;;
             *) VM="$PWD/$2"
            ;;
         esac
          shift
         ;;
      -*) VMOPTIONS="$VMOPTIONS $1 $2"
         shift
         ;;
      *)  IMOPTIONS="$IMOPTIONS $1 $2"
         shift
         ;;
   esac
   shift
    done
fi

# do not crash on dbus errors
export DBUS_FATAL_WARNINGS=0

# make Compose input methods work
[ -z "$LC_ALL" ] && export LC_ALL="$LANG"

VMOPTIONS="$VMOPTIONS -vm-sound-alsa"

# VM, Image, and Document are non-optional
# Document has to be present even if empty for IMOPTIONS to work
echo Executing: $WRAPPER "$VM" $VMOPTIONS "$IMAGE" "$DOCUMENT" $IMOPTIONS
exec $WRAPPER "$VM" $VMOPTIONS "$IMAGE" "$DOCUMENT" $IMOPTIONS


which is considerably more complicated than what @ked came up with to launch Scratch :)

However, it may simply be that all the above does boil down to the simpler script and that we can use it without any issues :)

Or maybe this script isn't what Scratch uses to launch itself but its the most promising candidate I can find :)

Just need a bash guru to go through it and tell us what's happening :)

Simon
Seeking help with Scratch and I/O stuff for Primary age children
http://cymplecy.wordpress.com/ @cymplecy on twitter
Posts: 2112
Joined: Fri Feb 24, 2012 6:19 pm
Location: Euxton, Lancashire, UK
by proxima » Wed Oct 10, 2012 8:37 am
simplesi wrote:Just need a bash guru to go through it and tell us what's happening :)
Simon


I didn't get time last night (too busy writing my first Lunar Lander with my son) - will have a look in my lunchbreak today though. Would be good if we can at least find which option/command it is that makes the difference between working and not working, so then the real Scratch/Squeak experts have something more to go on. But in the meantime for anyone else reading this, the good news is that Scratch DOES WORK without sticky keys when ked's instructions are followed, even if we don't yet know why.
Posts: 30
Joined: Tue Sep 18, 2012 3:16 pm
by simplesi » Wed Oct 10, 2012 9:56 am
too busy writing my first Lunar Lander with my son

Lunar Lander??/ - don't impose your old way of thinking on next generation :)

It should be Mars Curiosity Lander sims nowadays :)
http://scratch.mit.edu/forums/viewtopic.php?id=104614
Seeking help with Scratch and I/O stuff for Primary age children
http://cymplecy.wordpress.com/ @cymplecy on twitter
Posts: 2112
Joined: Fri Feb 24, 2012 6:19 pm
Location: Euxton, Lancashire, UK
by proxima » Wed Oct 10, 2012 10:06 am
simplesi wrote:
too busy writing my first Lunar Lander with my son

Lunar Lander??/ - don't impose your old way of thinking on next generation :)

It should be Mars Curiosity Lander sims nowadays :)


I'm in! (Oh damn, missed the deadline... Sounds a good project for us anyway though...)
Posts: 30
Joined: Tue Sep 18, 2012 3:16 pm
by proxima » Wed Oct 10, 2012 1:04 pm
One step closer to finding out what the problem is - and also, this is a far easier temporary workaround for people in the meantime.

In the file /usr/bin/scratch, line 97 reads:

Code: Select all
 [ -z "$LC_ALL" ] && export LC_ALL="$LANG"


Commenting that line out (by putting a # at the start of it) makes the sticky-keys problem disappear.

Why? I've got absolutely no idea. According to the comment on the previous line, that line is supposed to "Make Compose input methods work". I don't know what that means either, and I don't have time for any more research/googling for now (that was my lunchbreak).

But maybe that helps one of the experts shed more light on this?
Posts: 30
Joined: Tue Sep 18, 2012 3:16 pm
by proxima » Fri Oct 12, 2012 8:45 am
More info: This turns out to be a problem with Scratch on Linux in general, NOT specific to Raspberry Pi. I've just replicated it on Scratch running on Ubuntu 12.04 LTS on an Intel desktop PC, so we can definitely get Raspberry Pi voltage issues out of the equation once and for all...

Also, the same workaround (comment out that one line) works on Ubuntu.

The problem is discussed on http://scratch.mit.edu/forums/viewtopic.php?pid=1416155#p1416155
Posts: 30
Joined: Tue Sep 18, 2012 3:16 pm
by simplesi » Fri Oct 12, 2012 9:36 am
Great work proxima :)

Simon
Seeking help with Scratch and I/O stuff for Primary age children
http://cymplecy.wordpress.com/ @cymplecy on twitter
Posts: 2112
Joined: Fri Feb 24, 2012 6:19 pm
Location: Euxton, Lancashire, UK
by robochrish » Fri Oct 12, 2012 10:10 pm
It wont let me save over the /usr/bin/scratch file. It says "can't open file to write ". I assumed tag that this was a permissions problem, so I changed the permissions of that file in the properties, but then I get an error saying "operation not permitted ". I tried logging in as root, but can't. Any suggestions?
Posts: 3
Joined: Tue Oct 09, 2012 9:45 pm
by simplesi » Fri Oct 12, 2012 11:13 pm
You should be able to just
Code: Select all
sudo nano /usr/bin/scratch


and do any mods that way

Simon
PS to experts - where is the real file - is it at /usr/bin/scratch or /usr/bin/X11/scratch ???? - I'm assuming there is some sort of hard/soft link somewhere that makes no difference to us grunts but it would be nice to know :)
Seeking help with Scratch and I/O stuff for Primary age children
http://cymplecy.wordpress.com/ @cymplecy on twitter
Posts: 2112
Joined: Fri Feb 24, 2012 6:19 pm
Location: Euxton, Lancashire, UK
by proxima » Sat Oct 13, 2012 7:26 am
simplesi wrote:PS to experts - where is the real file - is it at /usr/bin/scratch or /usr/bin/X11/scratch ?


On my Ubuntu system, and I assume the Pi is the same (can't get to the Pi at the moment, son's on it) the entire X11 directory is a link to /usr/bin. i.e. the contents of /usr/bin/X11 are identical to /usr/bin.

(It even includes an X11 directory, which includes an X11 directory ... etc).
Posts: 30
Joined: Tue Sep 18, 2012 3:16 pm
by ked » Sat Oct 13, 2012 7:22 pm
Not on the rpi atm but I usually do something like:

Code: Select all
$ file `which scratch`
/usr/bin/scratch: POSIX shell script text executable


The output tells me which file is used and what type of file it is. As you now know there is no Scratch exe as such, but if you didn't know then the fact that a shell script is doing the launching means yet another exe (or another script!) is going to get called and, often, the script will be doing some set-up before hand. Same for many other programs.
Posts: 40
Joined: Thu Aug 04, 2011 9:18 am
by simplesi » Sat Jan 12, 2013 11:40 pm
@proxima
I've added a link to this thread on the Wiki
http://elinux.org/Scratch_on_RPi
Simon
Seeking help with Scratch and I/O stuff for Primary age children
http://cymplecy.wordpress.com/ @cymplecy on twitter
Posts: 2112
Joined: Fri Feb 24, 2012 6:19 pm
Location: Euxton, Lancashire, UK
by Pi-face » Sat Jan 26, 2013 11:14 am
Can I just ask - does this problem manifest itself like when you press one key and the text types out hundreds of the same letter?

We're getting this in file naming in Scratch, but it also happened when logging in as 'startx'. The 'x' was repeated on one great big long line.
Posts: 14
Joined: Wed Jan 09, 2013 1:12 pm
by simplesi » Sat Jan 26, 2013 8:00 pm
AFAIK its just peculiar to Scratch, only happens when actively scanning for keyboard presses (e.g. doesn't happen in normal "If key pressed" command blocks) and is completely eliminated by the fix.
Sorry :(

Simon
Seeking help with Scratch and I/O stuff for Primary age children
http://cymplecy.wordpress.com/ @cymplecy on twitter
Posts: 2112
Joined: Fri Feb 24, 2012 6:19 pm
Location: Euxton, Lancashire, UK
by Pi-face » Sat Jan 26, 2013 8:48 pm
The fix mentioned above?
Posts: 14
Joined: Wed Jan 09, 2013 1:12 pm
by Pi-face » Sat Jan 26, 2013 9:09 pm
Even in the shell the keyboard sticks and does insane keystrokes.
Posts: 14
Joined: Wed Jan 09, 2013 1:12 pm
by proxima » Sun Jan 27, 2013 9:17 am
Sorry, that sounds like it may be a different problem. The bug discussed in this thread is specific to Scratch, and also happens on some Linux versions of Scratch too. The "workaround" above involves a change to the script that starts Scratch and sets its environment up for it. That workaround seems to work for Scratch (although I have no idea why), but definitely won't affect anything else on your system.

The good news is that your problem may be easier to solve. Have you checked the power supply to the Pi is good? Underpowered Pi's get all sorts of weird problems. Have you got a different keyboard you can try? Finally - I had a problem like that when I was trying to use a cordless keyboard / mouse. It was my first experiment with cordless devices, and I am now back to using USB devices that have cables, like nature intended...
Posts: 30
Joined: Tue Sep 18, 2012 3:16 pm