"Ignoring" messages

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!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
JeffO2013
Posts: 17
Joined: Thu Jun 27, 2013 7:41 pm

"Ignoring" messages

Post by JeffO2013 » Tue Aug 06, 2013 4:02 pm

Hi everyone,

Is there a way to have livecode ignore key presses during a certain period of time? I need the program to continue to execute other commands but also disregard any key presses during this phase. The keyDown code is set up similar to what is below:

on keyDown theKey
if theKey is K
then doSomething //this is a function in the code that tells what to do if the key is pressed
else if theKey is d
then doSomething
end if
end keyDown

I only need it to accept the d and k keys and ignore everything else, which it does from what I have tested. Now I need to limit when it accepts the d and k keys - after it's finished running some other code used to set up the screen.

Right now it runs the keyDown code whenever d or k is pressed. I need it to only register the key pressed given during the accepted time and ignore everything else.

Thanks for the help

Jeff

Klaus
Posts: 14216
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: "Ignoring" messages

Post by Klaus » Tue Aug 06, 2013 4:21 pm

Hi Jeff,

quick idea: Use a global variable that holds "the seconds" and fill it when needed (opencard or whenever)!

Code: Select all

on opencard
  global gStartSeconds
  put the seconds into gStartSeconds
  ## More opencard stuff here...
end opencard
Then you can do something like this:

Code: Select all

on keyDown theKey
  global gStartSeconds
  ## Say you want to STOP entering data after 60 secs after you started the app:
  if the seconds - gStartSeconds >= 60 then
    beep
    exit keydown
  end if
  switch theKey
    case "K"
      doSomething //this is a function in the code that tells what to do if the key is pressed
      break
    case "d" 
     doSomething
      break
  end switch
end keyDown
Hint: ALWAYS use QUOTES around strings, like the values of theKey in this case!


Best

Klaus

JeffO2013
Posts: 17
Joined: Thu Jun 27, 2013 7:41 pm

Re: "Ignoring" messages

Post by JeffO2013 » Tue Aug 06, 2013 5:23 pm

Thank you Klaus! This will work nicely with me current code.

And thanks for the hint, but what might happen without the quotations? I've run it several time through using the code without quotations and haven't noticed anything unusual.

Thanks!

Jeff

Klaus
Posts: 14216
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: "Ignoring" messages

Post by Klaus » Tue Aug 06, 2013 5:36 pm

Hi Jeff,

the engine is less and less "forgiving" worth every new version, as I had experienced in the past,
so sticking to the correct syntax will not hurt now but save some headache in the future :-)


Best

Klaus

Post Reply