Menu

Keyboard

Gwenn

Keyboard

Classes and Methods

cogpy.Keyboard()

      Handler class for dealing with Keyboard I/O.

      press( key=None, shift=False, alt=False, ctrl=False, windows=False, cmd=False )

            Trigger-style function--waits until the specified key has been pressed, then returns.

            When the key is pressed, will set the cogpy.Experiment output value to key.

            Note: Keyboard.press should only be called in a yield statement within a cogpy.Experiment instance. Will
            return a generator function otherwise.

            If one or more of the modifier parameters (shift, alt, ctrl, windows, cmd) are set to True, then the
            corresponding keys must be down when key is pressed for the function to return.

            The key parameter will accept all common keyboard keys and characters, with the exception of the "fn"/"opt"
            key and the "print screen"/"print" key. All numpad keys should be prefaced with "num" (e.g.: "num1", "num+",
            "numleft"). If key is None, the function will return when any recognized key is pressed.

      get_key( key )

            Returns True if the specified key is currently pressed, False otherwise.

            The key parameter will accept all common keyboard keys and characters, with the exception of the "fn"/"opt"
            key and the "print screen"/"print" key. All numpad keys should be prefaced with "num" (e.g.: "num1", "num+",
            "numleft").


Example Usage

import cogpy

class Test(cogpy.Experiment):
    display = cogpy.Display()
    keyboard = cogpy.Keyboard()

    def start(self):
        yield keyboard.press("g",ctrl=True)
        print self.output
        print keyboard.get_key("g")
        yield keyboard.press("$")

exp = Test()
exp.run()

Interpreter output:

g
True

Related

Wiki: Home

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.