C# 使用sendkeys.sendwait()模拟键盘,输出汉字到dos下出错

xusen1013 2014-08-25 10:25:56
使用sendwait("中国“);提示
System.ComponentModel.Win32Exception: 拒绝访问。
在 System.Windows.Forms.SendKeys.SendInput(Byte[] oldKeyboardState, Queue previousEvents)
在 System.Windows.Forms.SendKeys.Send(String keys, Control control, Boolean wait)
在 System.Windows.Forms.SendKeys.SendWait(String keys)
在 KeybdTest.Form1.button1_Click(Object sender, EventArgs e) 位置 D:\工作项目\KeybdTest\KeybdTest\Form1.cs:行号 50
在 System.Windows.Forms.Control.OnClick(EventArgs e)
在 System.Windows.Forms.Button.OnClick(EventArgs e)
在 System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
在 System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
在 System.Windows.Forms.Control.WndProc(Message& m)
在 System.Windows.Forms.ButtonBase.WndProc(Message& m)
在 System.Windows.Forms.Button.WndProc(Message& m)
在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
在 System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

但是sendwait("zhongguo123");正确
不知道怎么回事,网上收拾。net没有权限,我是wpf/c# winform来处理的
private void button1_Click(object sender, EventArgs e) {

this.Hide();
SendKeys.SendWait("徐瑟");//有错
SendKeys.SendWait("{Enter}");
}
...全文
548 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
xs767461 2014-09-17
  • 打赏
  • 举报
回复
试试这个钩子 http://www.cnblogs.com/Charles2008/archive/2010/04/05/1700094.html
xusen1013 2014-08-26
  • 打赏
  • 举报
回复
哎!还是没有找到答案
xusen1013 2014-08-25
  • 打赏
  • 举报
回复
引用 2 楼 Z65443344 的回复:
要么你就直接sendmessage发消息过去,要模拟键盘你就老老实实的发送键盘上有的按键
不知道请不要乱发言,肯定是可以的,我的程序开发机器上都可以,我换了一个机器出现这样的问题
於黾 2014-08-25
  • 打赏
  • 举报
回复
要么你就直接sendmessage发消息过去,要模拟键盘你就老老实实的发送键盘上有的按键
於黾 2014-08-25
  • 打赏
  • 举报
回复
既然你知道这是模拟键盘,键盘上有中国这两个键么??
zhouzangood 2014-08-25
  • 打赏
  • 举报
回复
失落的神庙 2014-08-25
  • 打赏
  • 举报
回复
如果只是权限问题 可尝试右键用管理员权限运行exe 如果可以解决 参考此文 http://www.cr173.com/html/11557_1.html
失落的神庙 2014-08-25
  • 打赏
  • 举报
回复
如果是一定要模拟的话。 可以尝试用 郑码。 即 按住 alt 加6个数字键  比如 釦 这个是按住alt 然后依次按下 1 2 3 4 5 6
失落的神庙 2014-08-25
  • 打赏
  • 举报
回复
是dos还是命令提示符 命令提示符的话可以后台传参 不需要 模拟输入。而且sendmessage是前台模拟。 这样很不好。

110,533

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧