I want to recieve keyboard and mouse input in GTK+. For keyboard input, I tried using the accelgroup but it wasn't somehow as smooth as say SDL or SFML. When I pressed a key. It responded, paused for some time, responded again, pause for sometime and so on. By Mouse input I mean getting the position of the Mouse at a given time and whether a mouse button is clicked. By keyboard input I want to track keypresses and releases. I am using GTK+ and cairo for an Educational Graphics Program. Kind of like the Turtle Graphics. Any Help? Or Any third party library (C or C++) that works with GTK+ and tracks keyboard and mouse input?
相关问题
- Sorting 3 numbers without branching [closed]
- Multiple sockets for clients to connect to
- How to compile C++ code in GDB?
- Why does const allow implicit conversion of refere
- thread_local variables initialization
According to the docs]1 you can get mouse motion events setting them a mask of
GDK_POINTER_MOTION_MASK
- that means you will get motion events even though no buttons are pressed. Also, Gtk+ tutorials show some notion of utilizing mouse motion events.What do you mean by this? I think you are describing key repeat behaviour (the same as in a text editor when you press 'a' and hold it, you get 'aaaaaaaaaaaaa'. To disable it in your app:
Here is an example code demonstration of how to use callbacks to register mouse movement and key presses:
What you want to do is moderately complex. Take a look at
http://developer.gnome.org/gtk-tutorial/2.90/
and especially at
http://developer.gnome.org/gtk-tutorial/2.90/x344.html
and
http://developer.gnome.org/gtk-tutorial/2.90/c2422.html
The second link has source code for a keyboard callback that seems to do what you want. The third link is the beginning of a tutorial for a simple drawing program that uses the mouse.
EDIT: For the sake of completeness, I'll mention that the gtkglext library supports the use of OpenGL within GTK+. See
http://projects.gnome.org/gtkglext/