4 Replies Latest reply on Jun 13, 2006 3:05 PM by Itico

    Keyboard Announcement Tool

    Itico
      Hey folks, I am making what I thought was going to be a quick little tool to assist a few of my completely blind friend's clients in learning the keyboard. However, when trying to announce certain keys, they don't react the same. In the attempt to get them to work, I have finally whittled it down so the computer will announce the <, >, ?, and ! keys, but only if you rapidly alternate the keys. Otherwise, it announces 'Shift'.

      I'm going to drop the code here, so if you can't help me, thanks anyway. Anyone with ideas, pleae help so I can go on with my life! (Week and a half for a project I thought would take a day!)

      Code attached.

      Thanks.

      -- Lingo to Follow
      property theString

      on enterFrame me
      if (_key.shiftDown = TRUE) then
      member("Character").text = string("Shift")
      announceString(string("Shift"))
      end if
      if (_key.controlDown = TRUE) then
      member("Character").text = string("Control")
      announceString(string("Control"))
      end if
      if (_key.optionDown = TRUE) then
      member("Character").text = string("ALT")
      announceString(string("ALT"))
      end if
      end keyUp

      on keyDown
      end enterFrame

      on exitFrame me
      go to the frame
      end

      on keyUp
      case (the key) of
      ",": theString = "Comma"
      ".": theString = "Period"
      "/": theString = "Forward Slash"
      otherwise: theString = the key
      end case
      case (_key.keyCode) of
      024: theString = "Equals"
      ... (Lines Removed For Sanity)
      126: theString = "Up Arrow"
      otherwise: nothing
      end case
      member("Character").text = string(the key)
      if (_key.shiftDown = TRUE) then
      case (the key) of
      "!": theString = "Exclamation"
      "?": thestring = "Question Mark"
      "<": theString = "Lesser Than"
      ">": theString = "Greater Than"
      end case
      end if
      if (the key <> "Shift") then
      announceString(theString)
      else
      announceString("Shift")
      end if
      end keyDown

      on announceString thisString
      if (thisString <> "") then
      voiceSpeak(thisString)
      end if
      end announceString
        • 1. Re: Keyboard Announcement Tool
          Level 7
          Not sure if it matters, but a couple of your "end"s don't match your "on"s.
          You have "on EnterFrame" ended by "end keyUp", and "on keyUp" ended by "end
          keyDown". Probably doesn't matter. I always end every function with just
          "end", so I don't think anything that comes after that makes any difference.

          As for your other problem, it appears that you're executing the code
          checking for CTRL, ALT, and SHIFT every single frame, instead of just when
          the key is initially hit. You should add variables to make it only do these
          calls once when you first hit the key, and reset only when the key is
          released. So, for example:

          if (_key.shiftDown = TRUE) then
          if shiftHit = 0 then
          shiftHit = 1
          member("Character").text = string("Shift")
          announceString(string("Shift"))
          end if
          else shiftHit = 0

          Do this for the CTRL/COMMAND and ALT/OPTION as well, and it should work
          better, hopefully.


          • 2. Re: Keyboard Announcement Tool
            Itico Level 1
            Thank you Mr. Hoffman for your noticing. No, the 'end' statements don't reallly matter. They are just helpful for navigation. I will be fixing it, however, because I've written some complex stuff and it helps keep me where I should be.

            I am using the frame script because, from my experience anyway, I can not use keyPressed, keyUp or keyDown to detect the modifier keys. Therefore, I must check them as often as I can since I need them to activate immediately when they are struck.

            I have been considering code that is similar to yours to 'deactivate' the shift key after another key had been pressed. It just handn't occurred to me yet. And, I'm still not a hundred percent on how I'd do it.

            Thanks for your assistance.

            Have a wonderful day.
            • 3. Re: Keyboard Announcement Tool
              Level 7
              > I have been considering code that is similar to yours to 'deactivate' the
              > shift key after another key had been pressed. It just handn't occurred to
              me
              > yet. And, I'm still not a hundred percent on how I'd do it.

              Well, don't just 'deactivate' it when another key is pressed. 'Deactivate'
              it as soon as the program gets the message that it's down, otherwise you'll
              end up with it calling the shift-announce every single frame that the key is
              down instead of just once. In fact, I'd expect that you'd hear a stuttering
              sound, like "Sh-sh-sh-sh-sh-sh-sh-shift", repeating the beginning over and
              over until the key is released. Unless the voiceSpeak command just holds
              off until whatever's in the cue is finished playing before doing the next
              line, in which case it would instead just keep saying "Shift shift shift
              shift shift" over and over until it ran out the cue, long after you release
              the key. (Haven't used that function much, so I'm not sure which would
              happen, but I'd assume it'd be one or the other.)

              Anyhow, since the Shift, Ctrl, Alt (or Shift, Command, Option) keys don't
              register keyUp and keyDown events like regular keys, you have to handle that
              yourself, and using a variable for each of these keys like in my example
              should do the trick. Consider yourself lucky. In other programming
              languages I've used, I had to handle ALL the keys that way, since they
              didn't have keyUp and keyDown functions at all.


              • 4. Re: Keyboard Announcement Tool
                Itico Level 1
                Well, luckily, I am only detecting shifted characters. Anyway, yes, when a character is struck, I will change a variable like you suggested, which will 'turn off' the shift detection.

                Thanks for the help.