<s> from __future__ import division , print_function , unicode_literals <EOL> import sys <EOL> import os <EOL> sys . path . insert ( <NUM_LIT:0> , os . path . join ( os . path . dirname ( __file__ ) , '<STR_LIT:..>' ) ) <EOL> import cocos <EOL> from cocos . director import director <EOL> import pyglet <EOL> class KeyDisplay ( cocos . layer . Layer ) : <EOL> is_event_handler = True <EOL> def __init__ ( self ) : <EOL> super ( KeyDisplay , self ) . __init__ ( ) <EOL> self . text = cocos . text . Label ( "<STR_LIT>" , x = <NUM_LIT:100> , y = <NUM_LIT> ) <EOL> self . keys_pressed = set ( ) <EOL> self . update_text ( ) <EOL> self . add ( self . text ) <EOL> def update_text ( self ) : <EOL> key_names = [ pyglet . window . key . symbol_string ( k ) for k in self . keys_pressed ] <EOL> text = '<STR_LIT>' + '<STR_LIT:U+002C>' . join ( key_names ) <EOL> self . text . element . text = text <EOL> def on_key_press ( self , key , modifiers ) : <EOL> """<STR_LIT>""" <EOL> self . keys_pressed . add ( key ) <EOL> self . update_text ( ) <EOL> def on_key_release ( self , key , modifiers ) : <EOL> """<STR_LIT>""" <EOL> self . keys_pressed . discard ( key ) <EOL> self . update_text ( ) <EOL> class MouseDisplay ( cocos . layer . Layer ) : <EOL> is_event_handler = True <EOL> def __init__ ( self ) : <EOL> super ( MouseDisplay , self ) . __init__ ( ) <EOL> self . posx = <NUM_LIT:100> <EOL> self . posy = <NUM_LIT> <EOL> self . text = cocos . text . Label ( '<STR_LIT>' , font_size = <NUM_LIT> , x = self . posx , y = self . posy ) <EOL> self . add ( self . text ) <EOL> def update_text ( self , x , y ) : <EOL> text = '<STR_LIT>' % ( x , y ) <EOL> self . text . element . text = text <EOL> self . text . element . x = self . posx <EOL> self . text . element . y = self . posy <EOL> def on_mouse_motion ( self , x , y , dx , dy ) : <EOL> """<STR_LIT>""" <EOL> self . update_text ( x , y ) <EOL> def on_mouse_drag ( self , x , y , dx , dy , buttons , modifiers ) : <EOL> """<STR_LIT>""" <EOL> self . update_text ( x , y ) <EOL> def on_mouse_press ( self , x , y , buttons , modifiers ) : <EOL> """<STR_LIT>""" <EOL> self . posx , self . posy = director . get_virtual_coordinates ( x , y ) <EOL> self . update_text ( x , y ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> director . init ( resizable = True ) <EOL> director . run ( cocos . scene . Scene ( KeyDisplay ( ) , MouseDisplay ( ) ) ) </s>
