answersLogoWhite

0


Best Answer

So far the only event used is the on_draw event. To react to keyboard and mouse events, it's necessary to write and attach event handlers for these events as well: import pyglet window = pyglet.window.Window() @window.event def on_key_press(symbol, modifiers): print 'A key was pressed' @window.event def on_draw(): window.clear() pyglet.app.run()

Keyboard events have two parameters: the virtual key symbol that was pressed, and a bitwise combination of any modifiers that are present (for example, the CTRL and SHIFT keys).

The key symbols are defined in pyglet.window.key: from pyglet.window import key @window.event def on_key_press(symbol, modifiers): if symbol == key.A: print 'The "A" key was pressed.' elif symbol == key.LEFT: print 'The left arrow key was pressed.' elif symbol == key.ENTER: print 'The enter key was pressed.'

See the pyglet.window.key documentation for a complete list of key symbols.

Mouse events are handled in a similar way: from pyglet.window import mouse @window.event def on_mouse_press(x, y, button, modifiers): if button == mouse.LEFT: print 'The left mouse button was pressed.'

The x and y parameters give the position of the mouse when the button was pressed, relative to the lower-left corner of the window.

There are more than 20 event types that you can handle on a window. The easiest way to find the event name and parameters you need is to add the following line to your program: window.push_handlers(pyglet.window.event.WindowEventLogger())

This will cause all events received on the window to be printed to the console.

User Avatar

Wiki User

12y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Write a program for event handling mouse and keyboard events?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

How you write a c program in notepad?

Use the keyboard.


The distance between two cities in km is input through the keyboard write a program to convert and print this distance in meters feet inches and centimeters?

mesh's basic salary is input through the keyboard. his dearness allowance is 40% of basic salarying , and house rent allowance is 20% of basic salaried. write a program to calculate his gross salary


How do you write a research paper on an iPad?

Use a word processing program like Apple Pages. You should get a Bluetooth keyboard if you expect to do a lot of typing.


How do you write keyboard notes of malare song?

how to write keyboard notes of Malare song of Premam movie


Why recursive solution is better for tree traversal?

Because a tree is a recursive data-structure. It's easier to write (and easier to understand) a recursive program for handling it.


How do you type a multiplication sign if your keybaord doesn?

you can't write a multiplication mark on a keyboard but you can write a division one. first hold ALT and type 246 (÷) :) The letter 'x'. If using a program like Excel, use *.


How does a microprocessor work in a microwave?

embedded control computerIt is easier to write a computer program handling all these various functions than to design a dedicated hardware control system to do it.


How do you write a power of a number on the keyboard?

That really depends where you want to write it - in what program. For example, in Microsoft Word or Microsoft Excel, you can go to character format, and select "superscript". The shortcut key (at least in Word) is Ctrl-Shift-Plus.


How do you write on WeeWorld?

Use your keyboard. :P


How do you write numerals on the computer?

with the keyboard letters


How do you write a essay about patriotism?

you type it on the keyboard


How do you write your name in bubble letters on the keyboard?

Elpida