如何知道键盘在文本输入中是否处于活动状态 [英] How to know if the keyboard is active on a text input

查看:107
本文介绍了如何知道键盘在文本输入中是否处于活动状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,它的作用类似于屏幕上的键盘,我需要它知道是否在任何地方都有活动的键盘光标(插入符号),因此键盘将设置为活动状态.

I have an application that acts like an on screen keyboard, I need it to know if there is a keyboard cursor (caret) active any where, so the keyboard will set to active.

我已经搜索了键盘钩子和winapi,但是找不到合适的方法.

I have searched for keyboard hooks and winapi, but I couldn't find the proper method to use.

为简化我的问题,如果用户可以按真实键盘上的键并在计算机上打印文本,则我的应用程序必须处于活动状态.

To simplify my problem, I need my application to be active if the user can press on the real keyboard and print text on the computer.

推荐答案

通过搜索插入符位置很容易,因为它应该大于0

It is easy by searching for the caret position, since it should be larger than 0

    GUITHREADINFO lpgui = new GUITHREADINFO();
    IntPtr fore = GetForegroundWindow();
    uint tpid = GetWindowThreadProcessId(fore, IntPtr.Zero);
    lpgui.cbSize = Marshal.SizeOf(lpgui.GetType());
    bool flag = GetGUIThreadInfo(tpid, out lpgui);
    WINDOWINFO pwi = new WINDOWINFO();
    pwi.cbSize = (uint)Marshal.SizeOf(pwi.GetType());
    GetWindowInfo((IntPtr)lpgui.hwndCaret, ref pwi);

    if (flag)
    {
        if (!(lpgui.rcCaret.Location.X == 0 && lpgui.rcCaret.Location.Y == 0))
        {


            //TODO

        }
    }

这篇关于如何知道键盘在文本输入中是否处于活动状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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