# Copyright (c) 2009 Nokia Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import keycapture
import appuifw
import e32
import key_codes

# Map containing key_code : Key name
key_code_map = dict([[hex_value, key_name]
                     for key_name, hex_value in key_codes.__dict__.items()
                     if key_name[0] == 'E'])

t = appuifw.Text(u"Press a key (Test for 20 secs)\n")
appuifw.app.body = t


def key_callback(key):
    t.clear()
    t.add(u"\nKey pressed: key_codes.%s (%s)" % (key_code_map[key], key))

capturer = keycapture.KeyCapturer(key_callback)
capturer.keys = keycapture.all_keys
capturer.forwarding = 0

capturer.start()
e32.ao_sleep(20)
capturer.stop()
