简体   繁体   English

您如何在c#中模拟键入?

[英]How Do You Simulate Typing in c#?

I am thinking of making a few video turorials on C#, my problem is that I don't type very fast and I don't want to put the user to sleep as they watch me typing in real-time. 我正在考虑在C#上制作一些视频教程,我的问题是我的打字速度不是很快,并且在用户观看我实时键入内容时,我不想让用户入睡。

I would like to write a small C# program that will take a line of text and feed it to the keyboard buffer, so that I can simulate keyboard typing. 我想编写一个小的C#程序,它将一行文本输入到键盘缓冲区中,这样我就可以模拟键盘打字了。

Does anyone know how to access the keboard buffer to do this? 有人知道如何访问keboard缓冲区吗?

If this has been done before or if someone knows of an existing program to do this, can you point me in the right direction. 如果这是之前完成的,或者有人知道已有程序可以执行此操作,那么您能为我指明正确的方向吗?

Thanks. 谢谢。

You should use SendKeys, i can show you how to use 您应该使用SendKeys,我可以告诉您如何使用

here is an example: SendKeys.Send('A'); 这是一个示例: SendKeys.Send('A');

but u can use it with your own character: SendKeys.Send(CHARACTER HERE); 但您可以将其与您自己的字符一起使用: SendKeys.Send(CHARACTER HERE);

what happens if we have a string variable, you will get nothing 如果我们有一个字符串变量会发生什么,您将一无所获

if it happens use it this way: 如果发生这种情况,请使用以下方式:

string letter = "exampleletter";
foreach (char ch in letter) 
   SendKeys.Send(ch.ToString());

i hope it works for you 我希望这个对你有用

Yogibear 瑜伽熊

在我参加过的PDC和其他会议上,他们充分利用了代码片段来快速将新代码放入适当的位置。

You could use SendKeys Class 您可以使用SendKeys类

Provides methods for sending keystrokes to an application. 提供用于将击键发送到应用程序的方法。

I'm not really sure that you can write to keyboardbuffer or something like this 我不太确定您可以写键盘缓冲区或类似的东西

what I know it to send to some windows some keyboard commands in your case it will be sending keyboard commands to notepad probably in that case use the function provided above 我所知道的是在您的情况下向某些窗口发送一些键盘命令的过程,可能是将键盘命令发送到记事本的情况下,使用上面提供的功能

but I would recommend to cut video parts (typing moments) out of your video instead of writing code in C# 但我建议您从视频中剪切视频部分(键入时间),而不要用C#编写代码

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM