?? sec-gdkevent.html
字號:
<span class="STRUCTNAME">GDK_BUTTON_PRESS</span> </p> </li> <li> <p> <span class="STRUCTNAME"> GDK_3BUTTON_PRESS</span> </p> </li> <li> <p> <span class="STRUCTNAME"> GDK_BUTTON_RELEASE</span> </p> </li> </ol> <p> The X server automatically causes a pointer grab when a button is pressed, and releases it when it is released. This means that the button release event always goes to the same window that received the button press event. Xlib allows you to change this behavior, but GDK does not. (In the Xlib documentation, this automatic grab is referred to as a "passive" grab. It's distinct from an "active" grab initiated with <tt class="FUNCTION"> gdk_pointer_grab()</tt>, described in <a href= "sec-gdkcursor.html#SEC-POINTERGRAB">the section called <i>Grabbing the Pointer</i></a>.) </p> <p> A button event is defined as follows: </p> <table border="0" bgcolor="#E0E0E0" width="100%"> <tr> <td><pre class="PROGRAMLISTING"> typedef struct _GdkEventButton GdkEventButton;struct _GdkEventButton{ GdkEventType type; GdkWindow *window; gint8 send_event; guint32 time; gdouble x; gdouble y; gdouble pressure; gdouble xtilt; gdouble ytilt; guint state; guint button; GdkInputSource source; guint32 deviceid; gdouble x_root, y_root;}; </pre> </td> </tr> </table> <p> Button events are marked with a time stamp (<span class= "STRUCTNAME">time</span>) by the X server. The time is given in milliseconds of "server time"; every few weeks the integer overflows and timestamps begin again at 0. Thus, you should not rely on the value as an absolute measure of time; it is intended only to determine relative time between events. </p> <p> The mouse pointer's X and Y coordinates (relative to the window the event occurred in) are included in <span class="STRUCTNAME">GdkEventButton</span>. Keep in mind that the pointer may be outside the window (if a pointer grab is in effect; see <a href="sec-gdkcursor.html">the section called <i>The Mouse Pointer</i></a>). If the pointer is outside the window, its coordinates could be negative or larger than the window's size. Coordinates are given as doubles rather than integers, because some input devices such as graphics tablets have sub-pixel resolution. For most purposes, you will want to cast the doubles to integers. <span class="STRUCTNAME"> pressure</span>, <span class="STRUCTNAME">xtilt</span>, and <span class="STRUCTNAME">ytilt</span> are also special features of some input devices; they can be ignored almost all the time. </p> <p> The <span class="STRUCTNAME">state</span> member of <span class="STRUCTNAME">GdkEventButton</span> indicates which modifier keys or mouse buttons were held down an instant before the button was pressed. It is a bitfield, with one or more of the flags in <a href= "sec-gdkevent.html#TAB-MODMASKS">Table 5</a> set. Since the modifiers are read just before the button press, it follows that button press events do not have the pressed button in <span class="STRUCTNAME">state</span>, but button release events do have it. </p> <p> Be careful to check for the presence of certain bit masks, rather than the exact value of <span class= "STRUCTNAME">state</span>. That is, prefer this: </p> <table border="0" bgcolor="#E0E0E0" width="100%"> <tr> <td><pre class="PROGRAMLISTING"> if ( (state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK ) </pre> </td> </tr> </table> <p> and avoid this: </p> <table border="0" bgcolor="#E0E0E0" width="100%"> <tr> <td><pre class="PROGRAMLISTING"> if ( state == GDK_SHIFT_MASK ) </pre> </td> </tr> </table> <p> If you check the exact value of <span class="STRUCTNAME"> state</span>, your application will mysteriously stop working if the user has Num Lock or some other obscure modifier turned on. </p> <div class="TABLE"> <a name="TAB-MODMASKS"></a> <p> <b>Table 5. Modifier Masks for Key and Button Events</b> </p> <table border="1" bgcolor="#E0E0E0" cellspacing="0" cellpadding="4" class="CALSTABLE"> <tr> <th align="LEFT" valign="TOP"> Modifier Mask </th> <th align="LEFT" valign="TOP"> Meaning </th> </tr> <tr> <td align="LEFT" valign="TOP"> <span class="STRUCTNAME">GDK_SHIFT_MASK</span> </td> <td align="LEFT" valign="TOP"> Shift </td> </tr> <tr> <td align="LEFT" valign="TOP"> <span class="STRUCTNAME">GDK_LOCK_MASK</span> </td> <td align="LEFT" valign="TOP"> Caps Lock </td> </tr> <tr> <td align="LEFT" valign="TOP"> <span class="STRUCTNAME">GDK_CONTROL_MASK</span> </td> <td align="LEFT" valign="TOP"> Control </td> </tr> <tr> <td align="LEFT" valign="TOP"> <span class="STRUCTNAME">GDK_MOD1_MASK</span> </td> <td align="LEFT" valign="TOP"> Mod1 (often Meta or Alt) </td> </tr> <tr> <td align="LEFT" valign="TOP"> <span class="STRUCTNAME">GDK_MOD2_MASK</span> </td> <td align="LEFT" valign="TOP"> Mod2 </td> </tr> <tr> <td align="LEFT" valign="TOP"> <span class="STRUCTNAME">GDK_MOD3_MASK</span> </td> <td align="LEFT" valign="TOP"> Mod3 </td> </tr> <tr> <td align="LEFT" valign="TOP"> <span class="STRUCTNAME">GDK_MOD4_MASK</span> </td> <td align="LEFT" valign="TOP"> Mod4 </td> </tr> <tr> <td align="LEFT" valign="TOP"> <span class="STRUCTNAME">GDK_MOD5_MASK</span> </td> <td align="LEFT" valign="TOP"> Mod5 </td> </tr> <tr> <td align="LEFT" valign="TOP"> <span class="STRUCTNAME">GDK_BUTTON1_MASK</span> </td> <td align="LEFT" valign="TOP"> Button 1 </td> </tr> <tr> <td align="LEFT" valign="TOP"> <span class="STRUCTNAME">GDK_BUTTON2_MASK</span> </td> <td align="LEFT" valign="TOP"> Button 2 </td> </tr> <tr> <td align="LEFT" valign="TOP"> <span class="STRUCTNAME">GDK_BUTTON3_MASK</span> </td> <td align="LEFT" valign="TOP"> Button 3 </td> </tr> <tr> <td align="LEFT" valign="TOP"> <span class="STRUCTNAME">GDK_BUTTON4_MASK</span> </td> <td align="LEFT" valign="TOP"> Button 4 </td> </tr> <tr> <td align="LEFT" valign="TOP"> <span class="STRUCTNAME">GDK_BUTTON5_MASK</span> </td> <td align="LEFT" valign="TOP"> Button 5 </td> </tr> <tr> <td align="LEFT" valign="TOP"> <span class="STRUCTNAME">GDK_RELEASE_MASK</span> </td> <td align="LEFT" valign="TOP"> Key releases </td> </tr> </table> </div> <p> The <span class="STRUCTNAME">button</span> member of <span class="STRUCTNAME">GdkEventButton</span> indicates which button triggered the event (i.e., the button which was pressed or released). Buttons are numbered from one to five; most of the time, button one is the left button, button two is the middle button, and button three is the right button. Left-handed users might reverse these. Button four and five events are generated by some scroll wheel mice when you spin the scroll wheel; GTK+ attempts to send capture these events and move nearby scroll bars. You should probably ignore any events you receive for buttons four or five. </p> <p> The three standard mouse buttons have conventional meanings in Gnome. Button one is used for selection, drag and drop, and operating widgets: the most common tasks. Button three typically activates a pop-up menu. Button two is traditionally used to move objects, such as the panel. Sometimes button one moves objects also; for example, desktop icons can be moved with either button one or two. It is a good idea to be consistent with other applications whenever possible. </p> <p> The <span class="STRUCTNAME">source</span> and <span class="STRUCTNAME">deviceid</span> members are used to determine which device triggered the event; the user may have a graphics tablet and a mouse connected simultaneously, for example. You can ignore these fields unless you are writing an application that can take advantage of non-mouse devices. </p> <p> The last two members of <span class="STRUCTNAME"> GdkEventButton</span>, <span class="STRUCTNAME"> x_root</span> and <span class="STRUCTNAME">y_root</span>, are the <span class="STRUCTNAME">x</span> and <span class="STRUCTNAME">y</span> coordinates translated to be relative to the root window rather than the window receiving the event. You can use these as "absolute" coordinates to compare events from two different windows. </p> </div> <div class="SECT2"> <h2 class="SECT2"> <a name="Z120">Keyboard Events</a> </h2> <p> There are only two types of key event: <span class= "STRUCTNAME">GDK_KEY_PRESS</span> and <span class= "STRUCTNAME">GDK_KEY_RELEASE</span>. Some hardware does not generate key release events; you should not write code that depends on <span class="STRUCTNAME"> GDK_KEY_RELEASE</span> events, though your code should respond sanely if one is received. </p> <p> Here are the contents of a key event: </p> <table border="0" bgcolor="#E0E0E0" width="100%"> <tr> <td><pre class="PROGRAMLISTING"> typedef struct _GdkEventKey GdkEventKey;struct _GdkEventKey{ GdkEventType type; GdkWindow *window; gint8 send_event; guint32 time; guint state; guint keyval; gint length; gchar *string;}; </pre> </td> </tr> </table> <p> The first three members are the standard members from <span class="STRUCTNAME">GdkEventAny</span>; the <span class="STRUCTNAME">time</span> and <span class= "STRUCTNAME">state</span> members are identical to those found in <span class="STRUCTNAME">GdkEventButton</span>. </p> <p> <span class="STRUCTNAME">keyval</span> contains a <i class="FIRSTTERM">keysym</i>. The X server keeps a global translation table which converts combinations of physical keys and modifiers to keysyms. For example, the ke
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -