我对来自 c++ 的一段代码有一个新问题。我有一个按键来进行按键切换或类似的操作......也许代码会比我解释得更好:
while (1) {
Sleep (1);
if (GetAsyncKeyState(VK_TAB) & 1) {
toggle = !toggle;
if(toggle)
{
code here...();
}
else
{
code here...();
}
}
}
在 c++ 中一切都很好......但是移植到 C# - WPF,让我崩溃了。知道最简单的方法是什么吗?谢谢,
编辑2:为什么不工作?我已经注册了该操作的密钥..但没有开始。这是因为我已经在方法中了吗?
KeyboardHook hook = new KeyboardHook();
// take action on keys pressed.
hook.KeyPressed += new EventHandler<KeyPressedEventArgs>(fireUp);
// register the event that is fired after the key press.
hook.RegisterHotKey(ModKeys.None, Keys.Tab);
void fireUp(object sender, KeyPressedEventArgs e)
{
bool toggle = false;
toggle = !toggle;
byte[] byt = { 0xC7,0x83,0x1A,0x05,0x00,0x00,0x00,0x00,0x00,0x00 };
for (int i = 6; i < 10; ++i)
{
byt[i] = (byte)(atkSpd & 0xFF);
atkSpd = atkSpd >> 8;
}
if (toggle)
{
Write(vMemory + 8, byt, 10);
Write(vMemory, BitConverter.GetBytes((vMemory + 8)), 8);
Write(atkBase, new byte[] { 0xFF, 0x24, 0x25 }, 3);
Write(atkBase + 3, BitConverter.GetBytes((vMemory)), 4);
}
else
{
Write(atkBase, new byte[] { 0x66, 0x89, 0xB3, 0x1A, 0x05, 0x00, 0x00 }, 7);
}
}