zoukankan      html  css  js  c++  java
  • c# winform调用osk系统自带软键盘

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Runtime.InteropServices;
    using System.Diagnostics;
    using System.Windows.Forms;
    using NLog;
    
    
    namespace Utils.common
    {
        class ScreenKeyboard
        {
            private static ILogger logger = NLog.LogManager.GetCurrentClassLogger();
            public static bool isShowNumBoard = false;
    
            [DllImport("kernel32.dll", SetLastError = true)]
            public static extern bool Wow64DisableWow64FsRedirection(ref IntPtr ptr);
    
            [DllImport("kernel32.dll", SetLastError = true)]
            public static extern bool Wow64RevertWow64FsRedirection(IntPtr ptr);
    
            public static IntPtr ptr = new IntPtr();
    
            public static void ShowScreenKeyboard()
            {
                try {
                    //判断软键盘是否进程是否已经存在,如果不存在进行调用
                    Process[] pro = Process.GetProcessesByName("osk");
                    bool isWow64FsRedirectionDisabled = Wow64DisableWow64FsRedirection(ref ptr);
                   
                    //键盘如果已经打开则重新打开,防止最小化无法显示
                    if (pro != null && pro.Length > 0)
                    {
                        Process kbpr = pro[0];
                        kbpr.Kill();
                        if (isWow64FsRedirectionDisabled)
                        {
                            Process.Start(@"C:WINDOWSsystem32osk.exe");
                            Wow64RevertWow64FsRedirection(ptr);
                        }
                        return;
                    }
                    if (isWow64FsRedirectionDisabled)
                    {
                        Process.Start(@"C:WINDOWSsystem32osk.exe");
                        Wow64RevertWow64FsRedirection(ptr);
                    }
                }
                catch (Exception ex)
                {
                    logger.Error(ex.Message);
                }
            }
            
        }
    }
    

      

  • 相关阅读:
    [题解?]luogu_P1415拆分数列(dp(不懂
    [题解]luogu_P1070道路游戏(堆dp
    [题解]luogu_P2577午餐(贪心dp
    [题解]luogu_P2157学校食堂(状压dp
    [模板]线段树合并
    [题解]宝藏(状压
    [题解]NOI2010超级钢琴
    [题解]luogu_P2161_会场预约(线段树颜色相关
    【总结】LCA的4种求法
    SRM517-600加强版(DP)
  • 原文地址:https://www.cnblogs.com/webttt/p/15470511.html
Copyright © 2011-2022 走看看