当前位置: 首页 > article >正文

C#调用win10系统自带软键盘的方法

上次做了个笔记是关于调用windows系统自带的触摸键盘的方法:C#调用Windows系统自带触摸键盘的方法_c# 虚拟键盘-CSDN博客

除了调用触摸键盘,我们也可以通过调用win10的自带软键盘作为输入途径。

方法很简单。

1、添加using System.Diagnostics引用。

2、创建进程Process Winvirkey = Process.Start("osk.exe");

3、打开键盘:Winvirkey = Process.Start("osk.exe");

4、关闭键盘:Winvirkey.Kill();

具体实现如下:

using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using UnityEngine;

public class Win10key : MonoBehaviour
{
    Process Winvirkey;
    // Start is called before the first frame update
    void Start()
    {
        Winvirkey = Process.Start("osk.exe");
        Winvirkey.Kill();
    }

    // Update is called once per frame
    void Update()
    {
        if(Input.GetKeyDown(KeyCode.F1))
        {
            ShowKey();
        }
        else if(Input.GetKeyDown(KeyCode.F2))
        {
            HideKey();
        }
    }

    //打开虚拟键盘
    void ShowKey()
    {
        //此处需检测Winvirkey进程是否已关闭,否则打开状态再执行会报错
        if (Winvirkey.HasExited)
        {
            Winvirkey = Process.Start("osk.exe");
        }
    }

    //关闭虚拟键盘
    void HideKey()
    {
        //此处需检测Winvirkey进程是否已打开,否则关闭状态再执行会报错
        if (!Winvirkey.HasExited)
        {
            Winvirkey.Kill();
        }
    }
}

效果如下:C#调用软键盘_哔哩哔哩_bilibili


http://www.kler.cn/a/153067.html

相关文章:

  • 数据库应用:MongoDB 文档与索引管理
  • linux 安装 mvn
  • 长沙电信大楼火灾调查报告发布:系烟头引发。FIS来护航安全
  • [Ubuntu 18.04] RK3399搭建SSH服务实现远程访问
  • OBS Studio 30.0 正式发布:支持 WebRTC
  • 使用 Python 和 NLTK 进行文本摘要
  • 七牛云1024创建节-赛后有感
  • 点赞和关注功能
  • 从兔子说起:深入理解RabbitMQ基础概念【RabbitMQ 一】
  • 图书管理系统源码,图书管理系统开发,图书借阅系统源码四TuShuManager应用程序MVC控制器Controllers
  • sql中group by和having的使用
  • Git——工作区管理
  • OpenCV快速入门:彩蛋——小游戏制作
  • 大数据:Hadoop刷题
  • 创建SpringBoot Helloword 程序详细步骤
  • 【C++ Primer Plus学习记录】嵌套循环和二维数组
  • 营销系统规则引擎
  • uni-app+ts----微信小程序锚点定位 、自动吸顶、滚动自动选择对应的锚点(点击tab跳转对应的元素位置)
  • 基于Spring、SpringMVC、MyBatis的外卖点餐网站
  • 【数据结构】初识排序 直接插入排序