如何使用C#Win-App制作类似于Windows 7单屏键盘的键盘? [英] How Can I Make A Keyboard Like One-Screen Keyboard Of Windows 7 with C# Win-App ?

查看:81
本文介绍了如何使用C#Win-App制作类似于Windows 7单屏键盘的键盘?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带按钮的表格。我想按下键盘上的按钮而不是键盘上的W键,W键变为活动状态并写入记事本W。这很简单。



这个动作是否有任何类或方法。

I have a Form with a button . I want to press the Button in form instead of "W" key on keyboard and the "W" key become active and write in notepad "W". That's very simply .

Are there any Class or Method for this action.

推荐答案

[System.Runtime.InteropServices.DllImport("user32.dll", EntryPoint = "FindWindowEx")]
public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);

[System.Runtime.InteropServices.DllImport("User32.dll")]
public static extern int SendMessage(IntPtr hWnd, int uMsg, int wParam, string lParam);

public const int WM_SETTEXT = 0x000c;
internal void SendText(string content)
{
     var notepads = System.Diagnostics.Process.GetProcessesByName("notepad");

     // if Applicable, it runs Notepad Process
     //if (notepads.Length == 0)
     //    notepads = new System.Diagnostics.Process[]  System.Diagnostics.Process.Start("notepad") };

     if (notepads.Length > 0 && notepads[0] != null)
     {
         IntPtr child = FindWindowEx(notepads[0].MainWindowHandle, new IntPtr(0), "Edit", null);
         SendMessage(child, WM_SETTEXT, 0, content);
     }
}


这篇关于如何使用C#Win-App制作类似于Windows 7单屏键盘的键盘?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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