using System;
using System.Drawing;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Diagnostics;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
[DllImport("user32.dll")]
static extern bool SetForegroundWindow(IntPtr hWnd);
public Form1()
{
InitializeComponent();
}
const int w = 40;
const int h = 40;
const int x = 10;
const int y = 5;
string[] optkey = new string[]
{
"",
"+", //SHIFT
"^", //CTRL
"+^",//SHIFT+CTRL
"%" //ALT
};
private void Form1_Load(object sender, EventArgs e)
{
this.FormBorderStyle = FormBorderStyle.FixedToolWindow;
this.ClientSize = new Size(w*x, h*y);
for (int i = 0; i < y; i++)
{
for (int j = 0; j < x; j++)
{
Button button;
button = new Button();
button.Location = new Point(j * w, i * h);
button.Text = (i*x + j+1).ToString("00");
button.Size = new Size(w, h);
button.Tag = optkey[i] + (j + 1).ToString();
button.Click += new EventHandler(button_Click);
this.Controls.Add(button);
}
}
}
void button_Click(object sender, EventArgs e)
{
Process[] p = Process.GetProcessesByName("TVTest");
IntPtr hWnd = (IntPtr)p[0].MainWindowHandle;
SetForegroundWindow(hWnd);
SendKeys.Send(((Button)sender).Tag.ToString());
}
}
}
dXNpbmcgU3lzdGVtOwp1c2luZyBTeXN0ZW0uRHJhd2luZzsKdXNpbmcgU3lzdGVtLldpbmRvd3MuRm9ybXM7CnVzaW5nIFN5c3RlbS5SdW50aW1lLkludGVyb3BTZXJ2aWNlczsKdXNpbmcgU3lzdGVtLkRpYWdub3N0aWNzOwoKbmFtZXNwYWNlIFdpbmRvd3NGb3Jtc0FwcGxpY2F0aW9uMQp7CiAgICBwdWJsaWMgcGFydGlhbCBjbGFzcyBGb3JtMSA6IEZvcm0KICAgIHsKCiAgICAgICAgW0RsbEltcG9ydCgidXNlcjMyLmRsbCIpXQogICAgICAgIHN0YXRpYyBleHRlcm4gYm9vbCBTZXRGb3JlZ3JvdW5kV2luZG93KEludFB0ciBoV25kKTsKICAgICAgICBwdWJsaWMgRm9ybTEoKQogICAgICAgIHsKICAgICAgICAgICAgSW5pdGlhbGl6ZUNvbXBvbmVudCgpOwogICAgICAgIH0KICAgICAgICBjb25zdCBpbnQgdyA9IDQwOwogICAgICAgIGNvbnN0IGludCBoID0gNDA7CiAgICAgICAgY29uc3QgaW50IHggPSAxMDsKICAgICAgICBjb25zdCBpbnQgeSA9IDU7CiAgICAgICAgc3RyaW5nW10gb3B0a2V5ID0gbmV3IHN0cmluZ1tdCiAgICAgICAgewogICAgICAgICAgICAiIiwKICAgICAgICAgICAgIisiLCAvL1NISUZUCiAgICAgICAgICAgICJeIiwgLy9DVFJMCiAgICAgICAgICAgICIrXiIsLy9TSElGVCtDVFJMCiAgICAgICAgICAgICIlIiAgLy9BTFQKICAgICAgICB9OwogICAgICAgIHByaXZhdGUgdm9pZCBGb3JtMV9Mb2FkKG9iamVjdCBzZW5kZXIsIEV2ZW50QXJncyBlKQogICAgICAgIHsKICAgICAgICAgICAgdGhpcy5Gb3JtQm9yZGVyU3R5bGUgPSBGb3JtQm9yZGVyU3R5bGUuRml4ZWRUb29sV2luZG93OwogICAgICAgICAgICB0aGlzLkNsaWVudFNpemUgPSBuZXcgU2l6ZSh3KngsIGgqeSk7CiAgICAgICAgICAgIGZvciAoaW50IGkgPSAwOyBpIDwgeTsgaSsrKQogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICBmb3IgKGludCBqID0gMDsgaiA8IHg7IGorKykKICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgICBCdXR0b24gYnV0dG9uOwogICAgICAgICAgICAgICAgICAgIGJ1dHRvbiA9IG5ldyBCdXR0b24oKTsKICAgICAgICAgICAgICAgICAgICBidXR0b24uTG9jYXRpb24gPSBuZXcgUG9pbnQoaiAqIHcsIGkgKiBoKTsKICAgICAgICAgICAgICAgICAgICBidXR0b24uVGV4dCA9IChpKnggKyBqKzEpLlRvU3RyaW5nKCIwMCIpOwogICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgIGJ1dHRvbi5TaXplID0gbmV3IFNpemUodywgaCk7CiAgICAgICAgICAgICAgICAgICAgYnV0dG9uLlRhZyA9IG9wdGtleVtpXSArIChqICsgMSkuVG9TdHJpbmcoKTsKICAgICAgICAgICAgICAgICAgICBidXR0b24uQ2xpY2sgKz0gbmV3IEV2ZW50SGFuZGxlcihidXR0b25fQ2xpY2spOwogICAgICAgICAgICAgICAgICAgIHRoaXMuQ29udHJvbHMuQWRkKGJ1dHRvbik7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgdm9pZCBidXR0b25fQ2xpY2sob2JqZWN0IHNlbmRlciwgRXZlbnRBcmdzIGUpCiAgICAgICAgewogICAgICAgICAgICBQcm9jZXNzW10gcCA9IFByb2Nlc3MuR2V0UHJvY2Vzc2VzQnlOYW1lKCJUVlRlc3QiKTsKICAgICAgICAgICAgSW50UHRyIGhXbmQgPSAoSW50UHRyKXBbMF0uTWFpbldpbmRvd0hhbmRsZTsKICAgICAgICAgICAgU2V0Rm9yZWdyb3VuZFdpbmRvdyhoV25kKTsKICAgICAgICAgICAgU2VuZEtleXMuU2VuZCgoKEJ1dHRvbilzZW5kZXIpLlRhZy5Ub1N0cmluZygpKTsKICAgICAgICB9CiAgICB9Cn0K