2012-08-13 4 views
2

편집 : 아래 코드 조각이 작동합니다. 불행히도, 나는 시뮬레이터의 핵심 이벤트를 테스트 할 수 없으므로 실수로 전화에 잘못된 apk를 보냈습니다. 미안합니다. http://developer.coronalabs.com/reference/index/events/key/eventkeyname코로나에서 키 이벤트를 사용하는 방법?

내가 키 이벤트를 다시 검색 할 수 없습니다 그러나 :

여기 주어진이 코드를하려합니다. 내가 event.keyName 인쇄하려고하지만 그것을 안드로이드 장치에 다시 버튼을 건 감지하지 않습니다.

도와 주실 수 있습니까? 감사. 내 게임의

-- Key listener 
    local function onKeyEvent(event) 
     local phase = event.phase 
     local keyName = event.keyName 
     eventTxt.text = "("..phase.." , " .. keyName ..")" 

     if(keyName=="back") then 
     local a=display.newText("hello",100,600,nil,35) 
     end 
     -- we handled the event, so return true. 
     -- for default behavior, return false. 
     return true 
    end 

    -- Add the key callback 
    Runtime:addEventListener("key", onKeyEvent); 
+0

실제로 당신이 원하는 것은 다시 키 이벤트를 추적 ?? –

+0

예, 터치했을 때 이름을 인쇄하여 작동하는지 확인하고 싶습니다. if (keyName == "back") 다음 print ("hello") 끝 종류의 일. –

+1

코드를 게시하십시오! – SatheeshJM

답변

2

생산 코드 : 여기

내 코드입니다

function onBackButtonPressedAtMap(e) 
    if (e.phase == "down" and e.keyName == "back") then 
     --Here the key was pressed  
     downPress = true 
     return true 
    else 
     if (e.phase == "up" and e.keyName == "back" and downPress) then 
      --Here the key was released, put your print("hello!") here. 
      storyboard.gotoScene("mapscreen", "fade", 200); 
      --The next line is to disable this event 
      --so the key is not trapped anymore on the "mapscreen" 
      --because I want the back key make the APP quit. 
      Runtime:removeEventListener("key", onBackButtonPressedAtMap); 
      return true 
     end 
    end 
    return false; 
end 
+0

코드를 공유해 주셔서 감사합니다. 코드도 작동합니다. 나 (멍청한 나) 잘못된 AP 테스트. –

관련 문제