【问题标题】:How to Detect when entering a password field输入密码字段时如何检测
【发布时间】:2012-02-08 20:55:25
【问题描述】:

我目前正在尝试调试我在使用“matchbox-keyboard”(http://matchbox-project.org/) 程序时遇到的问题,希望能得到一些帮助。 matchbox-keyboard 是我目前在触摸屏信息亭中使用的屏幕键盘,允许用户输入一些基本输入以进行搜索等。它可能有点旧,但它仍然是我的应用程序的理想选择,因为它是一个“按需”键盘(即仅在需要时出现),轻巧,并且与我在设备上使用的 matchbox-window-manager 配合使用。但是,信息亭必须访问的站点之一要求用户临时登录,并且由于某种原因,每当用户单击密码字段时,屏幕键盘就会消失。

用户必须访问的站点无法更改,因此我决定尝试修补 matchbox-keyboard 以更改此行为。为此,我将问题追溯到代码中定义的自定义Atom,如下

typedef enum {
  MBKeyboardRemoteNone = 0,
  MBKeyboardRemoteShow,
  MBKeyboardRemoteHide,
  MBKeyboardRemoteToggle,
} MBKeyboardRemoteOperation;

=============

void
mb_kbd_remote_init (MBKeyboardUI *ui)
{
  Atom_MB_IM_INVOKER_COMMAND = XInternAtom(mb_kbd_ui_x_display(ui), 
                       "_MB_IM_INVOKER_COMMAND", False);
}

然后在 Xevents 中检查这个 Atom,然后使用来自 xevent (xevent->xclient.data.l[0]) 的数据来确定将键盘置于什么状态。我想不通的是 X 是如何显示的知道 Xevent 何时应该是 '_MB_IM_INVOKER_COMMAND' 类型,以及它如何实际设置数据值。具体来说,当我输入密码字段时,它如何/为什么将 xevent->xclient.data.l[0] 的值设置为 2 (MBKeyboardRemoteHide)。

我已尝试搜索代码以获取此处提到的关键对象的引用,并从此处的指南中阅读 Xlib 事件:http://tronche.com/gui/x/xlib/events/,并在 google 上搜索答案,但老实说,这只是有点结束我的头,我无法抓住这个问题。在这一点上,它已经不再是我的信息亭项目的必需品,而成为我的好奇心(在我弄清楚之前会让我发疯的东西),所以如果有人可以帮助我得到一些答案,我会非常感谢。

==========更新==========

进一步测试/信息:

问题似乎与浏览器实现无关,因为我在壁虎浏览器 (Firefox) 上尝试了我想要的网站以及只有文本和密码字段的基本测试 HTML 页面,以及webkit 浏览器(Midori),在两种浏览器中,在两个页面上,行为都是相同的。这是供参考的测试 HTML 页面:

<head>
</head>
<body>
    <form>
    Name: <input type="text" name="firstname"><br>
    PW: <input type="password" name="lastname">
    </form>
</body>
</html>

在我看来,密码字段出于某种原因故意拒绝焦点,因此直接单击该字段会导致调用 gtk-im 方法 focus-out。我怀疑它可能是 GTK 实现的一部分,可能与密码字段通常“隐藏”的行为有关。也许这样做是为了防止按需剪贴板存储密码或类似的东西?

通过单击密码字段和文本字段检查事件列表/调试输出时,每种字段类型的接收事件列表非常相似。许多事件是相同类型的,但它们之间存在一些差异,我仍在尝试解码。我知道事件编号在这种情况下几乎没有意义,但为了说明,这里是非密码字段的不同事件列表:

matchbox-keyboard-remote.c:47,mb_kbd_remote_process_xevents() got a message of type _MB_IM_INVOKER_COMMAND, val 1
matchbox-keyboard-ui.c:560,mb_kbd_ui_redraw() mark
matchbox-keyboard-remote.c:38,mb_kbd_remote_process_xevents() got a message, type 69206018
matchbox-keyboard-remote.c:38,mb_kbd_remote_process_xevents() got a message, type 69206018
matchbox-keyboard-remote.c:38,mb_kbd_remote_process_xevents() got a message, type 69206018
matchbox-keyboard-remote.c:38,mb_kbd_remote_process_xevents() got a message, type 37748776
matchbox-keyboard-remote.c:38,mb_kbd_remote_process_xevents() got a message, type 35651628
matchbox-keyboard-remote.c:38,mb_kbd_remote_process_xevents() got a message, type 35651629
matchbox-keyboard-remote.c:38,mb_kbd_remote_process_xevents() got a message, type 35682433
matchbox-keyboard-remote.c:38,mb_kbd_remote_process_xevents() got a message, type 69206018
matchbox-keyboard-remote.c:38,mb_kbd_remote_process_xevents() got a message, type 69206018

对于密码字段:

matchbox-keyboard-remote.c:47,mb_kbd_remote_process_xevents() got a message of type _MB_IM_INVOKER_COMMAND, val 2
matchbox-keyboard-ui.c:1230,mb_kbd_ui_event_loop() Hide timed out, calling mb_kbd_ui_hide
matchbox-keyboard-remote.c:38,mb_kbd_remote_process_xevents() got a message, type 69206018
matchbox-keyboard-remote.c:38,mb_kbd_remote_process_xevents() got a message, type 69206018
matchbox-keyboard-remote.c:38,mb_kbd_remote_process_xevents() got a message, type 69206018
matchbox-keyboard-remote.c:38,mb_kbd_remote_process_xevents() got a message, type 35651628
matchbox-keyboard-remote.c:38,mb_kbd_remote_process_xevents() got a message, type 35682433
matchbox-keyboard-remote.c:38,mb_kbd_remote_process_xevents() got a message, type 35665943
matchbox-keyboard-remote.c:38,mb_kbd_remote_process_xevents() got a message, type 39845918
matchbox-keyboard-remote.c:38,mb_kbd_remote_process_xevents() got a message, type 35651628
matchbox-keyboard-remote.c:38,mb_kbd_remote_process_xevents() got a message, type 35651629
matchbox-keyboard-remote.c:38,mb_kbd_remote_process_xevents() got a message, type 35682433

不幸的是,这是我目前获得的最好的信息,因为我的 C 技能相当生疏。

【问题讨论】:

    标签: c unix xlib


    【解决方案1】:

    matchbox-keyboard 安装一个 GTK 输入法(参见 gtk-im 目录)。它负责将消息发送到键盘。

    当输入法被告知焦点被移除时,它当前发送这个MBKeyboardRemoteHide命令(参见gtk-im/im-context.c)。

    XEvent 的处理而言,这只是一个ClientMessage,它允许客户端使用自己的“协议”在彼此之间进行通信。

    我无法解释的是,为什么当您单击密码字段时,您没有调用 focus_in vfunc。这可能是浏览器实现的一部分或GtkIMContext 问题。

    【讨论】:

    • 问题似乎与浏览器实现无关,因为我在壁虎浏览器 (Firefox) 上尝试了我想要的网站以及只有文本和密码字段的基本测试 HTML 页面,以及 webkit 浏览器(Midori),并且在两种浏览器中,在两个页面上,行为都是相同的。编辑我的问题以包含更多信息。
    猜你喜欢
    • 2016-03-23
    • 1970-01-01
    • 2020-03-27
    • 1970-01-01
    • 2020-07-24
    • 1970-01-01
    • 2012-07-07
    • 2018-02-14
    • 2011-01-25
    相关资源
    最近更新 更多