求用鼠标实现按住键盘某个键的效果 一直按住键盘某个键不放,程序会不断的触发keydown事件,我原来用这样的方法实现游戏的押分。现在居于成本考虑,想换成鼠标左键实现同样的效果,用timer来实现效果不是很理想。不知道各位有什么好的建议没? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 bool pressKey=true; System.Threading.Thread thread=null; private void Press() { while (pressKey) { SendKeys.SendWait("D"); System.Threading.Thread.Sleep(100); } }先这样然后 private void button1_Click(object sender, EventArgs e) { if (thread == null) { textBox1.Focus(); pressKey = true; thread = new System.Threading.Thread(new System.Threading.ThreadStart(Press)); thread.Start(); } else {//我这用这样比较保险了·· pressKey = false; thread.Abort(); thread = null; } }最后一个一定要加,要不忘记了就麻烦了 private void Form1_FormClosing(object sender, FormClosingEventArgs e) { if (thread != null) thread.Abort(); } 已完成程序的数据库连接问题 C#字符串替换问题 怎么读取App.config 下的appsettings 值??? 远程访问Oracle 10g的问题 用OracleClient,返回的DataSet有乱码及不完整问题,您是否也遇到过?谢谢! 新人刚刚学习C#,请教一个很简单的问题. VS制作安装包,让其执行ORCALE10G的脚本? dataset的奇怪问题,是BUG吗? 应用程序以ODBC连接方式查询DB2,预计执行时间超过允许的最大执行时间时该如何调整? 弱智问题啊winform编程中间怎么没有listbox的的控件啊? irisSkin2.dll的使用 全局变量的定义
System.Threading.Thread thread=null; private void Press()
{
while (pressKey)
{
SendKeys.SendWait("D");
System.Threading.Thread.Sleep(100);
}
}
先这样
然后 private void button1_Click(object sender, EventArgs e)
{
if (thread == null)
{
textBox1.Focus();
pressKey = true;
thread = new System.Threading.Thread(new System.Threading.ThreadStart(Press));
thread.Start();
}
else
{//我这用这样比较保险了··
pressKey = false;
thread.Abort();
thread = null;
} }最后一个一定要加,要不忘记了就麻烦了
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
if (thread != null)
thread.Abort();
}