使用GTK获取关键信息
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了使用GTK获取关键信息相关的知识,希望对你有一定的参考价值。
/*! * rief GTK Program to get information about key pressed * author Fabien Arcellier * * To compil with GTK : gcc -Wall `pkg-config --cflags gtk+-2.0` `pkg-config --libs gtk+-2.0` -o key_tool -g key_tool.c */ #include <gtk/gtk.h> static void destroy (GtkWidget*, gpointer); static gboolean key_press_event (GtkWidget*, GdkEventKey*, gpointer); int main(int argc, char *argv[]) { GtkWidget *window = NULL, *label= NULL; gtk_init(&argc, &argv); window = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_window_set_title (GTK_WINDOW (window), "Key Pressed tool"); gtk_container_set_border_width (GTK_CONTAINER (window), 10); gtk_widget_set_size_request (window, 300, 300); gtk_window_set_resizable (GTK_WINDOW (window), FALSE); label = gtk_label_new ("Press a key"); gtk_label_set_selectable (GTK_LABEL (label), TRUE); gtk_container_add (GTK_CONTAINER (window), label); gtk_widget_show_all (window); g_signal_connect (G_OBJECT (window), "key_press_event", G_CALLBACK (key_press_event), NULL); g_signal_connect (G_OBJECT (window), "destroy", G_CALLBACK (destroy), NULL); gtk_main(); return 0; } /*! * rief Close application */ static void destroy (GtkWidget *window, gpointer data) { gtk_main_quit(); } /*! * rief Display information about key pressed in label */ static gboolean key_press_event(GtkWidget *window, GdkEventKey *event, gpointer data) { char key_event_info[1024] = ""; char *event_string = NULL; GtkWidget *label = NULL; if (event -> string != NULL) { event_string = event -> string; } else { *event_string = '