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:\WINDOWS\system32\osk.exe");
                        Wow64RevertWow64FsRedirection(ptr);
                    }
                    return;
                }
                if (isWow64FsRedirectionDisabled)
                {
                    Process.Start(@"C:\WINDOWS\system32\osk.exe");
                    Wow64RevertWow64FsRedirection(ptr);
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex.Message);
            }
        }
        
    }
}

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM