Sorry, I forgot the original address.
Public class winiolab
{
Private const int kbc_key_cmd = 0x64;
Private const int kbc_key_data = 0x60;
[Dllimport ("winio32.dll")]
Private Static extern bool initializewinio ();
[Dllimport ("winio32.dll")]
Private Static extern bool getportval (intptr wportaddr, out int pdwportval, byte bsize );
[Dllimport ("winio32.dll")]
Private Static extern bool setportval (uint wportaddr, intptr dwportval, byte bsize );
[Dllimport ("winio32.dll")]
Private Static extern byte mapphystolin (byte pbphysaddr, uint dwphyssize, intptr physicalmemoryhandle );
[Dllimport ("winio32.dll")]
Private Static extern bool unmapphysicalmemory (intptr physicalmemoryhandle, byte pblinaddr );
[Dllimport ("winio32.dll")]
Private Static extern bool getphyslong (intptr pbphysaddr, byte pdwphysval );
[Dllimport ("winio32.dll")]
Private Static extern bool setphyslong (intptr pbphysaddr, byte dwphysval );
[Dllimport ("winio32.dll")]
Private Static extern void shutdownwinio ();
[Dllimport ("user32.dll")]
Private Static extern int mapvirtualkey (uint ucode, uint umaptype );
Private winiolab ()
{
Isinitialize = true;
}
Public static void initialize ()
{
If (initializewinio ())
{
Kbcwait4ibe ();
Isinitialize = true;
}
}
Public static void Shutdown ()
{
If (isinitialize)
Shutdownwinio ();
Isinitialize = false;
}
Private Static bool isinitialize {Get; set ;}
/// Wait for the keyboard buffer to be empty
Private Static void kbcwait4ibe ()
{
Int dwval = 0;
Do
{
Bool flag = getportval (intptr) 0x64, out dwval, 1 );
}
While (dwval & 0x2)> 0 );
}
/// Press the analog keyboard
Public static void keydown (Keys vkeycoad)
{
If (! Isinitialize) return;
Int btscancode = 0;
Btscancode = mapvirtualkey (uint) vkeycoad, 0 );
Kbcwait4ibe ();
Setportval (kbc_key_cmd, (intptr) 0xd2, 1 );
Kbcwait4ibe ();
Setportval (kbc_key_data, (intptr) 0x60, 1 );
Kbcwait4ibe ();
Setportval (kbc_key_cmd, (intptr) 0xd2, 1 );
Kbcwait4ibe ();
Setportval (kbc_key_data, (intptr) btscancode, 1 );
}
/// Simulate keyboard pop-up
Public static void keyup (Keys vkeycoad)
{
If (! Isinitialize) return;
Int btscancode = 0;
Btscancode = mapvirtualkey (uint) vkeycoad, 0 );
Kbcwait4ibe ();
Setportval (kbc_key_cmd, (intptr) 0xd2, 1 );
Kbcwait4ibe ();
Setportval (kbc_key_data, (intptr) 0x60, 1 );
Kbcwait4ibe ();
Setportval (kbc_key_cmd, (intptr) 0xd2, 1 );
Kbcwait4ibe ();
Setportval (kbc_key_data, (intptr) (btscancode | 0x80), 1 );
}
}
Call
Winiolab. initialize (); // register
Winiolab. keydown (Keys. a); // press
Winiolab. keyup (Keys. a); // release
Winiolab. Shutdown (); // log out after use