【问题标题】:Get the char that would be typed on `XKB_KEY_dead_circumflex` and normal key获取将在 `XKB_KEY_dead_circumflex` 和普通键上键入的字符
【发布时间】:2016-06-23 21:37:26
【问题描述】:

有没有办法确定它会解析哪个字符,例如如果我输入XKB_KEY_dead_circumflex 和char a?这里的结果将是â,但我怎样才能以编程方式检测到呢?

这不仅适用于XKB_KEY_dead_circumflex,还适用于例如也可以到XKB_KEY_dead_greek 输入希腊字母。

【问题讨论】:

  • 创建一个不可见的窗口并向其发送按键事件。

标签: linux keyboard x11


【解决方案1】:

在 X 中,此特定行为由输入法 (IM) 决定。 X 非常灵活;如果您愿意,您可以编写一个输入法,将XKB_KEY_dead_circumflexa 组合成日文。或者输出一个è,如果你想迷惑你的用户...

您可以尝试 XmbLookupString 或 Xutf8LookupString 来模拟按键并返回正确的字符:

XIM im= XOpenIM(display, NULL, NULL, NULL);
XIC ic = XCreateIC(im);

char buf[8];
KeySym symbol;
Status status;
XKeyPressedEvent event;
event.type = XKeyPressEvent;
event.display = display;
event.window = window;
event.state = 0; // optionally add Shift, Ctrl, Meta
event.keycode = XBK_KEY_dead_circumflex;
Xutf8LookupString(ic, &event, buf, 8, symbol, status); // send dead key
event.keycode = XBK_KEY_a;
Xutf8LookupString(ic, &event, buf, 8, symbol, status); // send real key

buf 现在应该包含 â 的 UTF8 代码,但请检查 status 以查看转换是否成功。

请注意,您必须传递“a”的键码,而不是“a”的 ASCII 码(我认为没有任何 X 函数接受死键和字符并返回组合)。您还必须只模拟 KeyPresses(请参阅 Xutf8LookupString 的手册页)。

【讨论】:

  • 不起作用:(。因此我在第一次调用“^”之后得到了第二个“a”
  • 您的主事件循环中是否有 XFilterEvent()?在这种情况下这很重要......
  • 我不知道。我将 GTK 用于 GUI 的东西
  • Xutf8LookupString 是无状态的。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-12-24
  • 2014-03-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-04-13
  • 1970-01-01
相关资源
最近更新 更多