使用GTK获取关键信息

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了使用GTK获取关键信息相关的知识,希望对你有一定的参考价值。

  1. /*!
  2.  * rief GTK Program to get information about key pressed
  3.  * author Fabien Arcellier
  4.  *
  5.  * 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
  6.  */
  7. #include <gtk/gtk.h>
  8.  
  9. static void destroy (GtkWidget*, gpointer);
  10. static gboolean key_press_event (GtkWidget*, GdkEventKey*, gpointer);
  11.  
  12. int main(int argc, char *argv[])
  13. {
  14. GtkWidget *window = NULL, *label= NULL;
  15.  
  16. gtk_init(&argc, &argv);
  17.  
  18. window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  19. gtk_window_set_title (GTK_WINDOW (window), "Key Pressed tool");
  20. gtk_container_set_border_width (GTK_CONTAINER (window), 10);
  21. gtk_widget_set_size_request (window, 300, 300);
  22. gtk_window_set_resizable (GTK_WINDOW (window), FALSE);
  23.  
  24. label = gtk_label_new ("Press a key");
  25. gtk_label_set_selectable (GTK_LABEL (label), TRUE);
  26.  
  27. gtk_container_add (GTK_CONTAINER (window), label);
  28. gtk_widget_show_all (window);
  29.  
  30. g_signal_connect (G_OBJECT (window), "key_press_event", G_CALLBACK (key_press_event), NULL);
  31. g_signal_connect (G_OBJECT (window), "destroy", G_CALLBACK (destroy), NULL);
  32.  
  33. gtk_main();
  34. return 0;
  35. }
  36.  
  37. /*!
  38.  * rief Close application
  39.  */
  40. static void destroy (GtkWidget *window, gpointer data)
  41. {
  42. gtk_main_quit();
  43. }
  44.  
  45. /*!
  46.  * rief Display information about key pressed in label
  47.  */
  48. static gboolean key_press_event(GtkWidget *window, GdkEventKey *event, gpointer data)
  49. {
  50. char key_event_info[1024] = "";
  51. char *event_string = NULL;
  52. GtkWidget *label = NULL;
  53.  
  54. if (event -> string != NULL)
  55. {
  56. event_string = event -> string;
  57. }
  58. else
  59. {
  60. *event_string = '';
  61. }
  62.  
  63. sprintf(key_event_info, "Key
  64. send_event : %d
  65. time : %d
  66. state : %d
  67. keyval : %d
  68. length : %d
  69. string : %s
  70. hardware_keycode : %d
  71. group : %d
  72. is_modifier %d",
  73. event -> send_event,
  74. event -> time,
  75. event -> state,
  76. event -> keyval,
  77. event -> length,
  78. event_string,
  79. event -> hardware_keycode,
  80. event -> group,
  81. event -> is_modifier
  82. );
  83.  
  84. label = gtk_bin_get_child (GTK_BIN (window));
  85. gtk_label_set_text (GTK_LABEL (label), key_event_info);
  86.  
  87. return TRUE;
  88. }

以上是关于使用GTK获取关键信息的主要内容,如果未能解决你的问题,请参考以下文章

如何从 adwords api 获取关键字状态信息

通过关键字获取漏洞平台最新漏洞信息

如何从统计中批量获取BD搜索关键词及对应的入口页面?

使用 Google Analytics 获取当前访问者的推荐人、付费/自然和关键字

表列表以及关键信息 - Oracle

GTK TextBuffer ,查找整个单词