InterviewSolution
| 1. |
How Do I Detect That A Mouse Or Keyboard Event Has Been Triggered? |
|
Answer» The correct way is to hook to some of the basic EVENT signals and then act upon receiving them. The signals you want to look for are:
However, many widgets don't have their event masks properly set, so they will ignore these events. The following example shows how it should be done for a GtkWindow, ADDING the necessary event masks, and then hooking to the signals. Note that you WOULD have to alter the wakeup function to handle the timer operations you would need for a screensaver. def wakeup(widget, event): Note that mouse "scroll-wheel" events are implemented as button clicks in the Xorg X11R6 server (button 4 for scroll up, button 5 for scroll down). The correct way is to hook to some of the basic event signals and then act upon receiving them. The signals you want to look for are: However, many widgets don't have their event masks properly set, so they will ignore these events. The following example shows how it should be done for a GtkWindow, adding the necessary event masks, and then hooking to the signals. Note that you would have to alter the wakeup function to handle the timer operations you would need for a screensaver. def wakeup(widget, event): Note that mouse "scroll-wheel" events are implemented as button clicks in the Xorg X11R6 server (button 4 for scroll up, button 5 for scroll down). |
|