【发布时间】:2014-01-17 10:54:23
【问题描述】:
我试图在我的程序中阻止输入,但它不起作用......我阅读了这篇文章,但没有找到解决方案,只有来自 vista-7 及以上 Windows 的问题...... 我也在这里找到了未解决的话题,我希望你能帮助我......
来自
的代码“先生。LeftTechticle”youtube video
他完美地运行了它......
我尝试了代码,但没有任何反应......
//------------------------------------------Block Class----------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace WindowsFormsApplication14
{
static class InputBlocker
{
[DllImport("user32.dll")]
static extern bool BlockInput(bool fBlockIt);
private static Timer timer = new Timer();
static InputBlocker()
{
timer.Tick += new EventHandler(tick);
}
public static void Block(int mill)
{
BlockInput(true);
timer.Interval = mill;
timer.Start();
}
private static void tick(object sender ,EventArgs e)
{
BlockInput(false);
timer.Stop();
}
}
}
//------------------------------------------Form class---------------------------------
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication14
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
InputBlocker.Block(10000);
}
}
}
【问题讨论】:
-
亲爱的 Vitor 如您所见,我正在输入代码问题不在于代码 Windows 7 系统的问题不适用于这些语句.. 有什么想法吗?
-
只是指出他们在那里谈论类似的问题。他们甚至有一个代码示例应该可以满足您的需求,但有人指出它在他们的 Windows 7 上不起作用。您是否尝试过返回
BlockInput(true)以查看它的true或false? -
嗨..我测试它是假的.. O.o 为什么会这样?