0
|
1 |
#
|
|
2 |
# keyviewer.py
|
|
3 |
#
|
|
4 |
# Copyright (c) 2005 Nokia Corporation
|
|
5 |
#
|
|
6 |
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
7 |
# you may not use this file except in compliance with the License.
|
|
8 |
# You may obtain a copy of the License at
|
|
9 |
#
|
|
10 |
# http://www.apache.org/licenses/LICENSE-2.0
|
|
11 |
#
|
|
12 |
# Unless required by applicable law or agreed to in writing, software
|
|
13 |
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
14 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15 |
# See the License for the specific language governing permissions and
|
|
16 |
# limitations under the License.
|
|
17 |
#
|
|
18 |
|
|
19 |
import appuifw
|
|
20 |
import graphics
|
|
21 |
import e32
|
|
22 |
|
|
23 |
keyboard_state={}
|
|
24 |
last_keycode=0
|
|
25 |
|
|
26 |
def draw_state():
|
|
27 |
canvas.clear()
|
|
28 |
canvas.text((0,12),u'Scancodes of pressed keys:',0x008000)
|
|
29 |
canvas.text((0,24),u' '.join([unicode(k) for k in keyboard_state if keyboard_state[k]]))
|
|
30 |
canvas.text((0,36),u' '.join([unicode(hex(k)) for k in keyboard_state if keyboard_state[k]]))
|
|
31 |
canvas.text((0,48),u'Last received keycode:', 0x008000)
|
|
32 |
canvas.text((0,60),u'%s (0x%x)'%(last_keycode,last_keycode))
|
|
33 |
|
|
34 |
def callback(event):
|
|
35 |
global last_keycode
|
|
36 |
if event['type'] == appuifw.EEventKeyDown:
|
|
37 |
keyboard_state[event['scancode']]=1
|
|
38 |
elif event['type'] == appuifw.EEventKeyUp:
|
|
39 |
keyboard_state[event['scancode']]=0
|
|
40 |
elif event['type'] == appuifw.EEventKey:
|
|
41 |
last_keycode=event['keycode']
|
|
42 |
draw_state()
|
|
43 |
|
|
44 |
canvas=appuifw.Canvas(event_callback=callback,
|
|
45 |
redraw_callback=lambda rect:draw_state())
|
|
46 |
appuifw.app.body=canvas
|
|
47 |
|
|
48 |
lock=e32.Ao_lock()
|
|
49 |
appuifw.app.exit_key_handler=lock.signal
|
|
50 |
lock.wait()
|