detecting for how long a key is being pressed

Nicolas Cueto nicolas_cueto at yahoo.com
Tue Sep 6 18:16:50 EDT 2005


Like Jacqueline, I too was going to suggest "keyDown"
and "keyUp". However I tried it out first myself and
found that so long as the targeted key is held conti-
nuously down:

1. the "keyDown" message is also generated continu-
ously. Thus, if the variable for storing the start time
is being set by the keyDown handler, then that variable
will be continuously reset. (To resolve this, I tried "if
tTimeVar is not empty then" to escape the handler, but
no luck)

2. the "keyUp" message is also being generated. I know
this because in the keyUp handler I have a "put x in field y"
line, which results in the field continuously blinking. (I would've
thought the keyUp message would be generated only after
the target key was released?)

Jacqueline also suggests that these key-handlers might be
system specific. In which case, I'm on Win2K.

Finally, I've appended my scripts below, in case someone
has a solution.

Cheers,
Nicolas Cueto
niconiko language school

### THE CARD SCRIPT

global gStartTime

on keyDown s
  put the long seconds into gStartTime
  pass keyDown -- TRIED BOTH WITH & W/OUT THIS LINE
end keyDown

### THE STACK SCRIPT

global gStartTime

on keyUp s
  put the long seconds into tEndTime
  put (tEndTime - gStartTime) into field "fResult" -- RESULTS IN A
BLINKING FIELD
end keyUp




More information about the use-livecode mailing list