simplegui_lib_keys — class to manage keyboard handling

(Version saved in CodeSkulptor https://py3.codeskulptor.org/#user305_EtIUDiM87dN1mD2.py .)

Examples of use in :

simplegui_lib_keys module.

A class to help manage keyboard handling in SimpleGUI of CodeSkulptor.

Piece of SimpleGUICS2Pygame. https://bitbucket.org/OPiMedia/simpleguics2pygame

license:GPLv3 — Copyright (C) 2014, 2020 Olivier Pirson
author:Olivier Pirson — http://www.opimedia.be/
version:May 19, 2020
class SimpleGUICS2Pygame.simplegui_lib_keys.Keys(frame, keys=None)[source]

Keys handler.

Set and catch keys handlers of SimpleGUICS2Pygame (and CodeSkulptor) to help.

General note: Some keyboards can’t handle more than two or three keys pressed simultaneously. See Keyboard Ghosting Explained! and Keyboard Ghosting Demonstration.

__init__(frame, keys=None)[source]

If keys is None then set an empty keys handler, else set a keys handler with key up and key down functions of keys.

active_handlers(), active_keydown_handler() or active_keyup_handler() must be called to activate.

Parameters:
  • frame – simplegui.Frame
  • keys – None or Keys
__weakref__

list of weak references to the object (if defined)

active_handlers()[source]

Active key down and key up handlers.

active_keydown_handler()[source]

Active the key down handler.

active_keyup_handler()[source]

Active the key up handler.

is_pressed(key_code)[source]

If the key is pressed then return True, else return False.

Parameters:key_code – int >= 0
Returns:bool
is_pressed_key_map(key_str)[source]

If the key is pressed then return True, else return False.

Parameters:key_str – str in simplegui.KEY_MAP
Returns:bool
pressed_keys()[source]

Return a sorted list with code of all pressed keys.

Returns:list of (int >= 0)
set_keydown_fct(key_code, fct=None)[source]

If fct is None then erase the function key down handler to the specified key, else set the function key down handler to the specified key.

Parameters:
  • key_code – int >= 0
  • fct – (int) -> *
set_keydown_fct_key_map(key_str, fct=None)[source]

If fct is None then erase the function key down handler to the specified key, else set the function key down handler to the specified key.

Parameters:
  • key_str – str in simplegui.KEY_MAP
  • fct – (int) -> *
set_keyup_fct(key_code, fct=None)[source]

If fct is None then erase the function key up handler to the specified key, else set the function key up handler to the specified key.

Parameters:
  • key_code – int >= 0
  • fct – (int) -> *
set_keyup_fct_key_map(key_str, fct=None)[source]

If fct is None then erase the function key up handler to the specified key, else set the function key up handler to the specified key.

Parameters:
  • key_str – str in simplegui.KEY_MAP
  • key_code – int >= 0
  • fct – (int) -> *

[source]