Okay, it's settled. I actually installed VC ++ to try the main keybd_event () function, and after working it, I was able to use it wisely in C #.
Here is the code, and surprisingly it is very simple. You will need to add this usage to your code in order to be able to import dll: using System.Runtime.InteropServices;
This code presses and holds the β1β button for 3 seconds, and then it is released for 1 second and repeats the process.
(code allocation messed up: /, copying from the "namespace ..." to the last parenthesis "}")
namespace ConsoleApplication1
{
class Program
{
[DllImport("user32.dll")]
static extern void keybd_event(byte bVk, byte bScan, uint dwFlags,UIntPtr dwExtraInfo);
static void Main(string[] args)
{
while (true)
{
keybd_event((byte)0x31, (byte)0x02, 0, UIntPtr.Zero);
Thread.Sleep(3000);
keybd_event((byte)0x31, (byte)0x82, (uint)0x2, UIntPtr.Zero);
Thread.Sleep(1000);
}
}
}
}
source
share