[comp.sys.mac.hypercard] OptionKey and ShiftKey STUCK down

helper@castle.ed.ac.uk (A Wilson) (03/04/91)

I need help with a hypercard problem.  I have written a
stack which tests students' responses to shapes on the
screen.  If the shape is longer on the left, they press the
Option key, if it is to the right they press the Shift key.

The tests work fine, but every so often, it seems that
hyprercard thinks that one or both of these keys are STUCK
down and as a result the stack assumes that the student has
answered by pressing the key which is stuck down.

Can anyone help? It is rather urgent because we intend to
use the stack as part of a lead levels in blood project and
we start testing next week.

I seem to be the only person at Edinburgh University who is
using hypercard to write stacks so I have no one to give me
any sort of technical suport.  I would really appreciate
some help as I have spent the whole weekend trying to fix
this problem.

The scripts for my stack are shown below:

=========================================================================

Arthur WIlson        | JANET  helper@uk.ac.edinburgh.castle
Computing Officer    | INTERNET helper%castle.ed.ac.uk@NSFNET-RELAY.ac.uk
Edinburgh University | UUCP 
The Main Library     | Telephone (UK) 031-650 3323  
George Square,       |
Edinburgh EH8 9LJ |  |
United Kingdom       |
=========================================================================



--------------------------STACK SCRIPTS-------------------------------

-- This stack shows the use a picture and records their response
-- either the shift key or the option key

on openstack
  global prees,subject
  put 2 into prees
  hide menubar
  hide bkgnd field score
  
  
  
end openstack

-- this starts the test

on starttest
  global correct, tcount,total,famil,tickscount,tcountsecs, rndno
  global subject,tests,dels,prees,matinput
  
  -- check that data is available for and if not, put some in  
  if card field matrix is empty then
    repeat 10 times
      put "1 2 3 4 5 6 7 8 9 10"&return before line 1 of B
      card field matrix
    end repeat
  end if
  
  put 0 into sntest
  set cursor to none
  put 2 into prees
  put 1 into famil
  
  -- check that the subject name is not greater the 4 chars
  if the number of chars of line 1 of card field snumb > 4 then
    show card field warning
    select line 1 of card field snumb
    exit starttest
  end if
  
  -- check that the subject name does not go over 1 line
  
  if the number of lines of card field snumb >1 then
    put "" into card field snumb
    select line 1 of card field snumb
    exit starttest
  end if
  -- make the subject name up to 4 digits long
  repeat while sntest is 0
    if the number of chars of card field snumb < 4 then
      put 0 before char 1 of card field snumb
    else
      put 1 into sntest
    end if
  end repeat
  
  put word 1 of line 1 of card field snumb into subject
  
  -- call the handler which runs the tests
  getfamiliar
  
  -- check that for the familiarity tests, the user gets 75% correct
  put prees/correct into aver
  repeat while aver>=1.25
    hide bkgnd field score of card "try again"
    hide bkgnd field corcount of card "try again"
    go to card "try again"
    put 0 into correct
    wait 5 second
    getfamiliar
    put prees/correct into aver
  end repeat
  
  go to card "before real"
  wait 5 seconds
  
  -- get the number of tests
  put the number of words of card field matrix of card setup B
  into prees
  put 2 into  tcount
  
  -- set the "famil" to 0 this means that it is a real test
  put 0 into famil
  put 0 into correct
  
  -- do the real tests
  getfamiliar
  
  -- write the results
  go to card results
  
end starttest


on getfamiliar
  global tcount, total,famil, tickscount,tcountsecs, rndno,subject,tests
  global dels, prees, correct,pausecount
  put 0 into total
  put 0 into tcountsecs
  put 0 into tnumb
  put 0 into correct
  put 0 into pausecount
  put "" into card field "a pause" of card blank
  
  -- do the familiarity tests
  if famil = 1 then
    put "This is a test" into card field "a test" of card left
    put "This is a test" into card field "a test" of card right
    put "This is a test" into card field "a test" of card blank
    go to card instructions
    wait 12 seconds
  else
    put "" into card field "a test" of card left
    put "" into card field "a test" of card right
    put "" into card field "a test" of card blank
  end if
  
  -- cycle for the number of tests
  repeat with tms = 1 to prees
    put pausecount+1 into pausecount
    put word tms of card field matrix of card setup B
    into tcountsecs
    go to card blank
    if pausecount is not 10 then
      show card picture
    end if
    set lockscreen to true
    beep
    wait 2 seconds
    
    -- get a random number 1 or 2
    put the random of 2 into rndno
    if rndno is 1 then
      go to card left
    end if
    if rndno is 2 then
      go to card right
    end if
    
  end repeat
  
end getfamiliar


-- this routine is called from the cards with the pictures on it
--  it show the picture and waits for the user to press the Shiftkey or
--  OptionKey 
-- if they do not respond it timesout
on showpicture
  global tcountsecs, tcount, correct, total, tickscount,famil,dels
  global subject,tests, rndno,pausecount
  put 0 into waitfor
  put 0 into keyhit
  put the shiftkey& the optionkey
  hide card picture
  hide background picture
  set cursor to none
  put return into rtn
  put total into bkgnd field score
  set lockscreen to false
  if famil is 1 then put 10 into tcountsecs
  
  -- if it is the tenth test then don't give a mask
  if pausecount is 10 then
    show card picture
    wait tcountsecs ticks
    hide card picture
  else
    show card picture
    wait tcountsecs ticks
    show background picture
  end if
  put the ticks into tstart
  repeat while waitfor is 0
    
    -- check for option key being down
    if the optionKey is down then
      put 1 into keyhit
      -- setting waitfor to # 0 takes you out the repeat
      put 1 into waitfor
      
    end if
    if the shiftKey is down then
      put 2 into keyhit
      -- setting waitfor to # 0 takes you out the repeat
      put 2 into waitfor
      
    end if
    put the ticks into tend
    
    if tend-tstart > 600 then
      put 0 into keyhit
      -- setting waitfor to # 0 takes you out the repeat
      put 3 into waitfor
    end if
    
  end repeat
  
  if rndno = keyhit then
    put 1 into corflag
    put correct+1 into correct
  else
    put 0 into corflag
    play "boing" "cs. f3"
    
  end if
  
  -- write the results away
  if famil is 0 then
    put the number of chars of card field results of card B
    results into fno
    put tcountsecs&&corflag&&rndno&&rtn after char fno of B
    card field results of card results
  end if
  
  put 0 into waitfor
  put 0 into keyhit
  
  wait 2 seconds
  
end showpicture


----------------------------------- START BUTTON SCRIPT-----------------

on mouseup
  starttest
end mouseup

---------------------------------PICTURE CARD SCRIPT----------------------

on opencard
  showpicture
end opencard

on closecard
  hide card picture
  hide background picture
end closecard

stadler@Apple.COM (Andy Stadler) (03/06/91)

In article <8835@castle.ed.ac.uk> helper@castle.ed.ac.uk (A Wilson) writes:

>I need help with a hypercard problem.  I have written a
>stack which tests students' responses to shapes on the
>screen.  If the shape is longer on the left, they press the
>Option key, if it is to the right they press the Shift key.

>The tests work fine, but every so often, it seems that
>hyprercard thinks that one or both of these keys are STUCK
>down and as a result the stack assumes that the student has
>answered by pressing the key which is stuck down.

Most likely, the repeated pressing of the shift key is activating the "sticky
keys" feature.  Sticky Keys is a part of the Universal Access package, a set
of utilities which facilitate use of the computer by people with reduced
physical capabilities.  Sticky Keys is specifically designed to allow use of
the keyboard by a person who can only press one key at a time (which would
preclude use of shift, option, or command).  It's activated by (does this
sound familiar?) pressing the shift key five times in a row without moving
the mouse or pressing any other keys.

Once activated, sticky keys works like this:  Each time you press a modifier
key, it "sticks" so the next key will be modified.  And if you press the 
modifier twice, it "locks" so an entire sequence of modified keys can be
typed.

To determine if this is what's messing your system up, watch the upper right-
hand corner of the screen while people are using your program.  If you see a
little icon appear, that's sticky keys at work.

How you can fix it:  There are a number of things you could do, including...
1.  Remove the "Easy Access" file from your system folder.
2.  Modify your test to not use the shift key.  Use Option or Command instead.
3.  Modify your test to require mouse movement or use of other keys.  Remember,
    it's five presses of the shift key with NO OTHER keyboard or mouse
    activity.

Hope this helps.

Andy Stadler
HyperCard IIGS Team
Apple Computer, Inc.