Excercise: Use of Keyboard keys • Program an application that uses the keyboard keys to trigger pop-up notes telling which
1. Use the keys module that provide the class for handing key events. from key_codes import * 2. Use canvas type from the appuifw module as appliation body. canvas=appuifw.Canvas(event_callback=keyboard.handle_event, redraw_callback=None) appuifw.app.body=canvas 3. Create a loop that constanly scans a key that is pressed. while running: if keyboard.pressed(EScancodeLeftArrow): 4. Exit the loop by pressing the exit key. Put therefore: app.exit_key_handler=quit def quit():
Example file: ex_use_of_keys.py Description: ex_use_of_keys_descr.py IMORTANT: when running the script, you have to press the navigation key left, right, up or down to see the result.
NOTE: check the "info: use of keyboard keys" site of this tutorial for checking the Key codes of all the different keys of the keyboard available or the API_Reference_for_Python.pdf.
If you are bored: use some of the previous spript and modify it so, that instead of using an "application menu" to trigger functions, it ues keyboard keys this time.
|
|
|
|