Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!
I have a program that is used to allow my biologist colleagues to watch animal behaviour videos and record the time and nature of 'behaviours' by a simple app that allows them to start record/capture key presses/check for specific keys/end recording/save file
It has worked well for years, but need some tweaks. When I fire it up in LiveCode, it no longer works. I used to trap the key pressed and the time in a field, but now, the keypresses seem to go the first field of the app, not the one I name. Here's the relevant bits..
on mouseUp
put empty into field "data"
put empty into field "lastLine"
beep
put the milliseconds into stTime
put the seconds into disTime
put false into stopNow
put true into clockRunning
put 0 into pauseStart
put 0 into pauseStop
put 0 into pauseInterval
end mouseUp
on keyDown theKey
put the milliseconds into keyTime
subtract stTime from keyTime
subtract pauseInterval from keyTime
put value(pauseInterval)/1000 into field "date"
switch
case theKey = "?"
put "Elapsed time: " && keyTime/1000 && "s elapsed" into field "lastLine"
break
case theKey="q"
send mouseUp to button "Stop"
break
default
put "Event:" && theKey && keyTime/1000 & return after field "Data"
set the scroll of field "Data" to the formattedHeight of field "Data"
put "Elapsed time:" && keyTime/1000 into field "lastLine"
end switch
end keyDown
Advice on capturing and redirecting keypress would be most welcome. Thank you.
You make several references to variables in the keyDown handler that are not valid. (ex.:subtract stTime from keyTime) Is there more to the script? Are these handlers in a field script? If so, is it locked? You cannot trap a mouseUp handler in an unlocked field, and you cannot type (directly, at least) into a locked one.
I tried to redo the app from the beginning, and it works, sort of! It is all about having the focus in the right place (i.e nowhere). It works, but one set up keypress too many, and it fails. I'd like to ask some kind soul if they could help. I'd send them the .livecode file.
Actually, just realised it can be uploaded here.
I'd welcome any insight about directing the key presses to the field "data"
Rob- your keydown handler is in the script of the Start button. The only keypresses that will capture are those going to the button, i.e., while the button has focus. When you click in the field, the field gets the focus and so you are no longer trapping the keydown events.
If you move your keydown handler into the card script it will do what you want, although it would be better in that situation to have the start and stop buttons set a flag that would enable the trapping.
That was some simple. Hindsight is a wonderful thing. My application is now doing what is required. hence, a rare and self-indulgent
Thanks to all of you who were gracious enough to take the time to address what turned out to be a very silly problem. I really need to think about inheritance!