Page 1 of 1

KeyDown only firing once

Posted: Thu Jul 15, 2021 11:53 am
by richmond62
What code can I use to stop multiple firing of a key when my finger gets stuck on it?

Re: KeyDown only firing once

Posted: Thu Jul 15, 2021 11:58 am
by Klaus
Maybe checking the last character in your field or wherever you type.
If it is the same as the currently pressed char...

Re: KeyDown only firing once

Posted: Thu Jul 15, 2021 12:03 pm
by richmond62
Not possible when the keyDown is being used for moving a graphic object round a stack in a game.

Re: KeyDown only firing once

Posted: Thu Jul 15, 2021 12:15 pm
by Klaus
True! :-)

Maybe you can post your script?

Re: KeyDown only firing once

Posted: Thu Jul 15, 2021 12:20 pm
by jmburnod
Hi friends,

If i understand correctly the goal, this script does the job

Code: Select all

local sStarttime,sPausetime
on opencard
   put the milliseconds into sStarttime
   put 500 into sPausetime
end opencard


on keydown pKey
   if tTime > (sStarttime + sPausetime) then
      put pkey after fld "fText"
   end if
   put the milliseconds into sStarttime
end keydown
Kind regards
Jean-Marc

Re: KeyDown only firing once

Posted: Thu Jul 15, 2021 1:10 pm
by richmond62
No, I am afraid that does not work:
-
Screen Shot 2021-07-15 at 3.07.59 PM.png
-
cardScript:

Code: Select all

on arrowKey AK
   put item 1 of the loc of grc "ANT" into LR
   put item 2 of the loc of grc "ANT" into UD
   switch AK
      case "up"
          set the backgroundpattern of grc "ANT" to the ID of img "A1.png"
         move grc "ANT" to LR,(UD-12)
         break
         case "down"
          set the backgroundpattern of grc "ANT" to the ID of img "A3.png"
         move grc "ANT" to LR,(UD+12)
         break
         case "left"
          set the backgroundpattern of grc "ANT" to the ID of img "A4.png"
         move grc "ANT" to (LR-12),UD
         break
         case "right"
          set the backgroundpattern of grc "ANT" to the ID of img "A2.png"
         move grc "ANT" to (LR+12),UD
         break
   end switch
   if intersect(grc"ANT",img"maze.png",4) then
      send "mouseUp" to btn "RESTART"
   end if
   if intersect(grc"ANT",img"block.png",4) then
      send "mouseUp" to btn "RESTART"
   end if
   --------
   if intersect(grc"ANT",img"f1",4) then
      add 1 to fld "SCORE"
      set the vis of img "f1" to false
      set the loc of img "f1" to -100,-100
   end if
   if intersect(grc"ANT",img"f2",4) then
      add 1 to fld "SCORE"
      set the vis of img "f2" to false
      set the loc of img "f2" to -100,-100
   end if
   if intersect(grc"ANT",img"f3",4) then
      add 1 to fld "SCORE"
      set the vis of img "f3" to false
      set the loc of img "f3" to -100,-100
   end if
   if intersect(grc"ANT",img"f4",4) then
      add 1 to fld "SCORE"
      set the vis of img "f4" to false
      set the loc of img "f4" to -100,-100
   end if
   if intersect(grc"ANT",img"f5",4) then
      add 1 to fld "SCORE"
      set the vis of img "f5" to false
      set the loc of img "f5" to -100,-100
   end if
   if intersect(grc"ANT",img"f6",4) then
      add 1 to fld "SCORE"
      set the vis of img "f6" to false
      set the loc of img "f6" to -100,-100
   end if
   if intersect(grc"ANT",img"f7",4) then
      add 1 to fld "SCORE"
      set the vis of img "f7" to false
      set the loc of img "f7" to -100,-100
   end if
   if intersect(grc"ANT",img"FINISH",4) then
      set the vis of img "bravo" to true
   end if
end arrowKey
A lot of that 'guff' after the switch statement is for the 'ant' to 'eat' things.

Re: KeyDown only firing once

Posted: Thu Jul 15, 2021 1:12 pm
by Klaus
AHA, and where is the KEYDOWN handler in question?

Re: KeyDown only firing once

Posted: Thu Jul 15, 2021 1:34 pm
by dunbarx
Can you use "keyUp" to do what you want? That method cannot get "stuck"

Craig

Re: KeyDown only firing once

Posted: Thu Jul 15, 2021 1:46 pm
by richmond62
Ouch! That's simple.

BUT, better to use rawKeyUp as one can trap the arrowKeys that way.

UP = 65362
LEFT = 65361
RIGHT = 65363
DOWN = 65364

Re: KeyDown only firing once

Posted: Thu Jul 15, 2021 4:44 pm
by Thunder
Hi !

Maybe the flushEvents can be of some help too..?

flushEvents : "Clears pending events from the event queue so they will not trigger handlers.!

Sincere
Thunder.

Re: KeyDown only firing once

Posted: Thu Jul 15, 2021 7:32 pm
by richmond62
flushEvents

Quite possibly, but not for 9-14 year olds who have been programming for less than 2 weeks.