问题描述
- 在iis调用windowsAPI的问题
-
菜鸟不知道问题是不是问的有漏洞,我出现的问题是用VS,c#web调用了windowsAPI,控制键盘,和获取键盘状态,在VS上的调用是成功的,可是发布到iis上点击按钮页面刷新后却并没有成功运行,求大神解答
解决方案
解决方案二:
你代码怎么写的?b/s系统你要调用客户端的windowsAPI有安全问题,你获取服务器端的又没有什么意思。。你要获取键盘输入,可以用js获取,onkeydown,onkeyup事件等。。
解决方案三:
public partial class WebForm1 : System.Web.UI.Page
{
[DllImport("user32.dll")]
static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, uint dwExtraInfo);
[DllImport("user32.dll",
CharSet = CharSet.Auto,
ExactSpelling = true,
CallingConvention = CallingConvention.Winapi)]
public static extern short GetKeyState(int keyCode);
bool ScrollLock = (((ushort)GetKeyState(0x91)) & 0xffff) != 0;
public static void press(byte i)
{
keybd_event(i, 0, 0, 0);
keybd_event(i, 0, 2, 0);
}
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
press(20);
if (Console.CapsLock)
{
TextBox1.Text = "C灯开启";
}
else
{
TextBox1.Text = "C灯关闭";
}
return ;
}
protected void Button3_Click(object sender, EventArgs e)
{
press(145);
if (ScrollLock==false)
{
TextBox3.Text = "S灯开启";
}
else
{
TextBox3.Text = "S灯关闭";
}
}
protected void Button2_Click(object sender, EventArgs e)
{
press(144);
if (Console.NumberLock)
{
TextBox2.Text = "N灯开启";
}
else
{
TextBox2.Text = "N灯关闭";
}
}
}
}
时间: 2024-11-17 05:05:42