如何在GTK中获得键盘和鼠标输入? [英] How do I get Keyboard and Mouse Input in GTK?

查看:113
本文介绍了如何在GTK中获得键盘和鼠标输入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在GTK +中接收键盘和鼠标输入。对于键盘输入,我尝试使用加速组,但它不像SDL或SFML那样流畅。当我按下一个键。它响应,暂停了一段时间,再次作出反应,停顿了一段时间,等等。通过鼠标输入我的意思是在给定的时间获取鼠标的位置以及是否单击鼠标按钮。通过键盘输入,我想跟踪按键和释放。我正在使用GTK +和开罗进行教育图形计划。有点像海龟图形。任何帮助?或任何第三方库(C或C ++),与GTK +一起使用并跟踪键盘和鼠标输入? 解决方案

做适度复杂。看一看



http:/ /developer.gnome.org/gtk-tutorial/2.90/



特别是

http://developer.gnome.org/gtk-tutorial/2.90/x344.html





http://developer.gnome.org/gtk-tutorial/2.90/c2422.html



第二个链接有一个键盘回调的源代码,它似乎可以做你想做的事情。第三个链接是使用鼠标的简单绘图程序教程的开始。

编辑:为了完整起见,我会提到gtkglext库支持在GTK +中使用OpenGL。见



http://projects.gnome.org/ gtkglext /


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?

解决方案

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/

这篇关于如何在GTK中获得键盘和鼠标输入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆