(self, args)
ON KEY: define key event trapping.
ON KEY: define key event trapping.
ON KEY : define key event trapping .
def on_event_gosub_(self, args):
        """ON KEY: define key event trapping."""
        token = next(args)
        num = next(args)
        jumpnum = next(args)
        if jumpnum == 0:
            jumpnum = None
        elif jumpnum not in self._program.line_numbers:
            raise error.BASICError(error.UNDEFINED_LINE_NUMBER)
        list(args)
        if token == tk.KEY:
            keynum = values.to_int(num)
            error.range_check(1, 20, keynum)
            self.key[keynum-1].set_jump(jumpnum)
        elif token == tk.TIMER:
            timeval = values.to_single(num).to_value()
            error.throw_if(timeval <= 0)
            period = round(timeval * 1000.)
            self.timer.set_trigger(period)
            self.timer.set_jump(jumpnum)
        elif token == tk.PLAY:
            playval = values.to_int(num)
            error.range_check(1, 32, playval)
            self.play.set_trigger(playval)
            self.play.set_jump(jumpnum)
        elif token == tk.PEN:
            self.pen.set_jump(jumpnum)
        elif token == tk.STRIG:
            strigval = values.to_int(num)
            ## 0 -> [0][0] 2 -> [0][1]  4-> [1][0]  6 -> [1][1]
            if strigval not in (0,2,4,6):
                raise error.BASICError(error.IFC)
            self.strig[strigval//2].set_jump(jumpnum)
        elif token == tk.COM:
            comnum = values.to_int(num)
            error.range_check(1, 2, comnum)
            self.com[comnum-1].set_jump(jumpnum)
def on_event_gosub_ ( self , args ) : token = next ( args ) num = next ( args ) jumpnum = next ( args ) if jumpnum == 0 : jumpnum = None elif jumpnum not in self . _program . line_numbers : raise error . BASICError ( error . UNDEFINED_LINE_NUMBER ) list ( args ) if token == tk . KEY : keynum = values . to_int ( num ) error . range_check ( 1 , 20 , keynum ) self . key [ keynum - 1 ] . set_jump ( jumpnum ) elif token == tk . TIMER : timeval = values . to_single ( num ) . to_value ( ) error . throw_if ( timeval <= 0 ) period = round ( timeval * 1000. ) self . timer . set_trigger ( period ) self . timer . set_jump ( jumpnum ) elif token == tk . PLAY : playval = values . to_int ( num ) error . range_check ( 1 , 32 , playval ) self . play . set_trigger ( playval ) self . play . set_jump ( jumpnum ) elif token == tk . PEN : self . pen . set_jump ( jumpnum ) elif token == tk . STRIG : strigval = values . to_int ( num ) ## 0 -> [0][0] 2 -> [0][1]  4-> [1][0]  6 -> [1][1] if strigval not in ( 0 , 2 , 4 , 6 ) : raise error . BASICError ( error . IFC ) self . strig [ strigval // 2 ] . set_jump ( jumpnum ) elif token == tk . COM : comnum = values . to_int ( num ) error . range_check ( 1 , 2 , comnum ) self . com [ comnum - 1 ] . set_jump ( jumpnum )