> I have had an awful time on my current project with Flash 
> eating keyboard commands, especially Tab.  I eventually had 
> to abandon Tab functionality entirely.

Ok, time for me to post the key handler I use. It catches tab, even with
a couple dozen Flash sprites, all with buttons.

It also traps for cmd-q and alt-F4.

First, I create an object:

me.pKeyHandler = new(script "Key Mapping Parent", me)

The Key Mapping Parent:

-- Generic Key Mapping Parent.
-- Description:  This object handles mapping keystrokes to actions

----
global kMachine

-- init my counters
on new me, ownerActivity
  -- init the keycodes for the special keys
  pF1 = 122 + 256
  pF2 = 120 + 256
  pF3 = 99 + 256
  pF4 = 118 + 256
  pF5 = 96 + 256
  pF6 = 97 + 256
  pF7 = 98  + 256
  pF8 = 100  + 256
  pF11 = 103 + 256
  pHomeKey = 115 + 256
  pEndKey = 119 + 256
  pQuitOK = TRUE -- in some special cases, we don't want to quit
  return me
end


-- this ancestor object traps key activity from user & passes it down.
on keyDown me
  set pCntlDown = the controlDown
  set pCmdDown = the commandDown
  set pOptDown = the optionDown
  
  set pKey = chartonum(the key)
  --  put "In keyDown script. pKey: " & pKey
  --  put "pCntlDown: " & pCntlDown
  --  put "pCmdDown: "& pCmdDown
  --  put "the keyCode: " & the keyCode
  
  set keyID = defineKey(me)
  doKey me, keyID
  
  set pActingOnKey = true
end


-- we use keyUp as a last-ditch to get the key stroke event.
-- (sometimes Flash movies seem to get in the way of our 'hearing' the
keydown).
on keyUp me
  if not pActingOnKey then keyDown me
  
  set pActingOnKey = false
end


on defineKey me
  -- We look at the keystroke differently if it's a Windows function or
special key
  -- First check to see if it's a special key
  pKeyCode = the keyCode
  if pKeyCode > 96  then --F5, the lowest value for a function key
    pKeyCode = pKeyCode + 256
    if kMachine = "Macintosh" then
      keyID = adjustMacKeys(me, pKeyCode)
      
    else
      keyID = adjustWinKeys(me, pKeyCode)
      
    end if
    
    return pKeyCode
  else
    -- it's not a special key, so use the key instead of the keycode
    if kMachine = "Macintosh" then
      keyID = adjustMacKeys(me, pKey)
      
    else
      keyID = adjustWinKeys(me, pKey)
      
    end if
    
    return keyID
  end if
end


on adjustMacKeys me, keyID
  
  if pCntlDown or the controlDown then -- funky catch-all for Macs.
hmph.
    
    set keyID = keyID + 256
    
  else if pCmdDown or the commandDown then -- commandDown.
    
    case keyID of
        
      113:
        if pQuitOK then AskQuit -- quit, command-q.
        
    end case
    
  end if
  
  return keyID
end


-- we have to handle option & control keys differently on Windows.
-- we just convert to the Mac equivalents before calling #doKey.
on adjustWinKeys me, keyID
  
  if pCntlDown or the controlDown then -- what the hell.  Win may not
get controlDown here, either.
    
    case keyID of
        
      29, 31, 28: -- right, down, and left arrows.
        keyID = keyID + 256
        
      113:
        if pQuitOK then ...  -- Ctrl-Q
        
      otherwise:
        set keyID = keyID + 160
        
    end case
    
  else if pOptDown or the optionDown then  -- optionDown.
    
    case keyID of
        
      pF4:
        if pQuitOK then doSomething -- quit, alt-F4.
        
    end case
    
  end if
  
  return keyID
End

on doKey me, keyID
  if voidP(keyID) then set keyID = defineKey(me)
  
  case keyID of
      
    13: -- Return key
      -- do something
      
    27: -- escape key.  
      -- do something

    27: -- tab key.  
      -- do something
            
  end case
  
end

[To remove yourself from this list, or to change to digest mode, go to 
http://www.penworks.com/lingo-l.cgi  To post messages to the list, email [EMAIL 
PROTECTED]  (Problems, email [EMAIL PROTECTED]). Lingo-L is for learning and helping 
with programming Lingo.  Thanks!]

Reply via email to