Имитация нажатия клавиш, исправить код - C#
Формулировка задачи:
Необходимо помочь, исправить этот код, так как я сам ученик, еще не понимаю где мои ошибки и как исправить...
Было бы замечательно взглянуть на готовый исходник, но и просто от исправленного кода не откажусь
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 MSRPbot
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
[DllImport("user32.dll")]
static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, UIntPtr dwExtraInfo);
//Нажимаем
keybd_event(0x01, 0, 0, UIntPtr.Zero);
//Ждем сколько надо
Thread.Sleep(1000);
//Отпускаем
keybd_event(0x01, 0, 0x02, UIntPtr.Zero);
}
}
}Ошибки:
Error 1 Invalid expression term '[' 21 13 MSRPbot Error 2 ; expected 21 14 MSRPbot Error 3 ; expected 21 37 MSRPbot Error 4 Invalid expression term ']' 21 37 MSRPbot Error 5 ; expected 21 38 MSRPbot Error 6 Invalid expression term 'static' 22 1 MSRPbot Error 7 ; expected 22 8 MSRPbot Error 8 Invalid expression term 'extern' 22 8 MSRPbot Error 9 ; expected 22 15 MSRPbot Error 10 Keyword 'void' cannot be used in this context 22 15 MSRPbot Error 11 Expected ; or = (cannot specify constructor arguments in declaration) 22 31 MSRPbot Error 12 Invalid expression term 'byte' 22 37 MSRPbot Error 13 ; expected 22 40 MSRPbot Error 14 Invalid expression term ',' 22 40 MSRPbot Error 15 ; expected 22 42 MSRPbot Error 16 Identifier expected; 'uint' is a keyword 22 54 MSRPbot Error 17 Cannot use more than one type in a for, using, fixed, or declaration statement 22 76 MSRPbot Error 18 ; expected 22 87 MSRPbot Error 19 Invalid expression term ')' 22 87 MSRPbotРешение задачи: «Имитация нажатия клавиш, исправить код»
textual
Листинг программы
void PressKey(byte keyCode)
{
const int KEYEVENTF_EXTENDEDKEY = 0x1;
const int KEYEVENTF_KEYUP = 0x2;
keybd_event(Keys.W, 0x45, KEYEVENTF_EXTENDEDKEY, 0);
keybd_event(Keys.W, 0x45, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0);
}