using System;
using System.Drawing;
using System.Media;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace TestProject
{
/// <summary>
/// 키보드 폼
/// </summary>
public partial class KeyBoardForm : NoActiveForm
{
//////////////////////////////////////////////////////////////////////////////////////////////////// Import
////////////////////////////////////////////////////////////////////////////////////////// Static
//////////////////////////////////////////////////////////////////////////////// Private
#region 키보드 이벤트 발생시키기 - keybd_event(virtualKey, scanCode, flag, extraInformation)
/// <summary>
/// 키보드 이벤트 발생시키기
/// </summary>
/// <param name="virtualKey">가상 키</param>
/// <param name="scanCode">스캔 코드</param>
/// <param name="flag">플래그</param>
/// <param name="extraInformation">추가 정보</param>
[DllImport("user32.dll")]
private static extern void keybd_event(byte virtualKey, byte scanCode, uint flag, int extraInformation);
#endregion
#region 후킹 초기화 하기 - InitHook(controlHandle)
/// <summary>
/// 후킹 초기화 하기
/// </summary>
/// <param name="controlHandle">컨트롤 핸들</param>
[DllImport("vkb.dll", CharSet = CharSet.Auto)]
private static extern void InitHook(IntPtr controlHandle);
#endregion
#region 후킹 설치하기 - InstallHook()
/// <summary>
/// 후킹 설치하기
/// </summary>
[DllImport("vkb.dll", CharSet = CharSet.Auto)]
private static extern void InstallHook();
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Field
////////////////////////////////////////////////////////////////////////////////////////// Private
#region Field
/// <summary>
/// 사운드 재생 여부
/// </summary>
private bool playSound = true;
/// <summary>
/// Caps Lock 버튼 눌림 여부
/// </summary>
private bool isPressedCAPSLOCK = false;
/// <summary>
/// Shift 버튼 눌림 여부
/// </summary>
private bool isPressedSHIFT = false;
/// <summary>
/// 한글 모드 여부
/// </summary>
private bool isHANGULMode = false;
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
////////////////////////////////////////////////////////////////////////////////////////// Public
#region 생성자 - KeyBoardForm()
/// <summary>
/// 생성자
/// </summary>
public KeyBoardForm()
{
InitializeComponent();
}
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Method
////////////////////////////////////////////////////////////////////////////////////////// Private
//////////////////////////////////////////////////////////////////////////////// Event
#region 폼 로드시 처리하기 - Form_Load(sender, e)
/// <summary>
/// 폼 로드시 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void Form_Load(object sender, EventArgs e)
{
Initialize();
this.k0101PictureBox.Click += keyPictureBox_Click;
this.k0102PictureBox.Click += keyPictureBox_Click;
this.k0103PictureBox.Click += keyPictureBox_Click;
this.k0104PictureBox.Click += keyPictureBox_Click;
this.k0105PictureBox.Click += keyPictureBox_Click;
this.k0106PictureBox.Click += keyPictureBox_Click;
this.k0107PictureBox.Click += keyPictureBox_Click;
this.k0108PictureBox.Click += keyPictureBox_Click;
this.k0109PictureBox.Click += keyPictureBox_Click;
this.k0110PictureBox.Click += keyPictureBox_Click;
this.k0111PictureBox.Click += keyPictureBox_Click;
this.k0112PictureBox.Click += keyPictureBox_Click;
this.k0113PictureBox.Click += keyPictureBox_Click;
this.k0114PictureBox.Click += keyPictureBox_Click;
this.k0115PictureBox.Click += keyPictureBox_Click;
this.k0116PictureBox.Click += keyPictureBox_Click;
this.k0117PictureBox.Click += keyPictureBox_Click;
this.k0201PictureBox.Click += keyPictureBox_Click;
this.k0202PictureBox.Click += keyPictureBox_Click;
this.k0203PictureBox.Click += keyPictureBox_Click;
this.k0204PictureBox.Click += keyPictureBox_Click;
this.k0205PictureBox.Click += keyPictureBox_Click;
this.k0206PictureBox.Click += keyPictureBox_Click;
this.k0207PictureBox.Click += keyPictureBox_Click;
this.k0208PictureBox.Click += keyPictureBox_Click;
this.k0209PictureBox.Click += keyPictureBox_Click;
this.k0210PictureBox.Click += keyPictureBox_Click;
this.k0211PictureBox.Click += keyPictureBox_Click;
this.k0212PictureBox.Click += keyPictureBox_Click;
this.k0213PictureBox.Click += keyPictureBox_Click;
this.k0214PictureBox.Click += keyPictureBox_Click;
this.k0215PictureBox.Click += keyPictureBox_Click;
this.k0216PictureBox.Click += keyPictureBox_Click;
this.k0217PictureBox.Click += keyPictureBox_Click;
this.k0301PictureBox.Click += keyPictureBox_Click;
this.k0302PictureBox.Click += keyPictureBox_Click;
this.k0303PictureBox.Click += keyPictureBox_Click;
this.k0304PictureBox.Click += keyPictureBox_Click;
this.k0305PictureBox.Click += keyPictureBox_Click;
this.k0306PictureBox.Click += keyPictureBox_Click;
this.k0307PictureBox.Click += keyPictureBox_Click;
this.k0308PictureBox.Click += keyPictureBox_Click;
this.k0309PictureBox.Click += keyPictureBox_Click;
this.k0310PictureBox.Click += keyPictureBox_Click;
this.k0311PictureBox.Click += keyPictureBox_Click;
this.k0312PictureBox.Click += keyPictureBox_Click;
this.k0313PictureBox.Click += keyPictureBox_Click;
this.k0401PictureBox.Click += keyPictureBox_Click;
this.k0402PictureBox.Click += keyPictureBox_Click;
this.k0403PictureBox.Click += keyPictureBox_Click;
this.k0404PictureBox.Click += keyPictureBox_Click;
this.k0405PictureBox.Click += keyPictureBox_Click;
this.k0406PictureBox.Click += keyPictureBox_Click;
this.k0407PictureBox.Click += keyPictureBox_Click;
this.k0408PictureBox.Click += keyPictureBox_Click;
this.k0409PictureBox.Click += keyPictureBox_Click;
this.k0410PictureBox.Click += keyPictureBox_Click;
this.k0411PictureBox.Click += keyPictureBox_Click;
this.k0412PictureBox.Click += keyPictureBox_Click;
this.k0413PictureBox.Click += keyPictureBox_Click;
this.k0501PictureBox.Click += keyPictureBox_Click;
this.k0502PictureBox.Click += keyPictureBox_Click;
this.k0503PictureBox.Click += keyPictureBox_Click;
this.k0504PictureBox.Click += keyPictureBox_Click;
this.k0505PictureBox.Click += keyPictureBox_Click;
this.k0506PictureBox.Click += keyPictureBox_Click;
this.k0507PictureBox.Click += keyPictureBox_Click;
this.k0508PictureBox.Click += keyPictureBox_Click;
this.k0509PictureBox.Click += keyPictureBox_Click;
this.k0510PictureBox.Click += keyPictureBox_Click;
this.k0511PictureBox.Click += keyPictureBox_Click;
this.k0101PictureBox.DoubleClick += keyPictureBox_DoubleClick;
this.k0102PictureBox.DoubleClick += keyPictureBox_DoubleClick;
this.k0103PictureBox.DoubleClick += keyPictureBox_DoubleClick;
this.k0104PictureBox.DoubleClick += keyPictureBox_DoubleClick;
this.k0105PictureBox.DoubleClick += keyPictureBox_DoubleClick;
this.k0106PictureBox.DoubleClick += keyPictureBox_DoubleClick;
this.k0107PictureBox.DoubleClick += keyPictureBox_DoubleClick;
this.k0108PictureBox.DoubleClick += keyPictureBox_DoubleClick;
this.k0109PictureBox.DoubleClick += keyPictureBox_DoubleClick;
this.k0110PictureBox.DoubleClick += keyPictureBox_DoubleClick;
this.k0111PictureBox.DoubleClick += keyPictureBox_DoubleClick;
this.k0112PictureBox.DoubleClick += keyPictureBox_DoubleClick;
this.k0113PictureBox.DoubleClick += keyPictureBox_DoubleClick;
this.k0114PictureBox.DoubleClick += keyPictureBox_DoubleClick;
this.k0115PictureBox.DoubleClick += keyPictureBox_DoubleClick;
this.k0116PictureBox.DoubleClick += keyPictureBox_DoubleClick;
this.k0117PictureBox.DoubleClick += keyPictureBox_DoubleClick;
this.k0201PictureBox.DoubleClick += keyPictureBox_DoubleClick;
this.k0202PictureBox.DoubleClick += keyPictureBox_DoubleClick;
this.k0203PictureBox.DoubleClick += keyPictureBox_DoubleClick;
this.k0204PictureBox.DoubleClick += keyPictureBox_DoubleClick;
this.k0205PictureBox.DoubleClick += keyPictureBox_DoubleClick;
this.k0206PictureBox.DoubleClick += keyPictureBox_DoubleClick;
this.k0207PictureBox.DoubleClick += keyPictureBox_DoubleClick;
this.k0208PictureBox.DoubleClick += keyPictureBox_DoubleClick;
this.k0209PictureBox.DoubleClick += keyPictureBox_DoubleClick;
this.k0210PictureBox.DoubleClick += keyPictureBox_DoubleClick;
this.k0211PictureBox.DoubleClick += keyPictureBox_DoubleClick;
this.k0212PictureBox.DoubleClick += keyPictureBox_DoubleClick;
this.k0213PictureBox.DoubleClick += keyPictureBox_DoubleClick;
this.k0214PictureBox.DoubleClick += keyPictureBox_DoubleClick;
this.k0215PictureBox.DoubleClick += keyPictureBox_DoubleClick;
this.k0216PictureBox.DoubleClick += keyPictureBox_DoubleClick;
this.k0217PictureBox.DoubleClick += keyPictureBox_DoubleClick;
this.k0301PictureBox.DoubleClick += keyPictureBox_DoubleClick;
this.k0302PictureBox.DoubleClick += keyPictureBox_DoubleClick;
this.k0303PictureBox.DoubleClick += keyPictureBox_DoubleClick;
this.k0304PictureBox.DoubleClick += keyPictureBox_DoubleClick;
this.k0305PictureBox.DoubleClick += keyPictureBox_DoubleClick;
this.k0306PictureBox.DoubleClick += keyPictureBox_DoubleClick;
this.k0307PictureBox.DoubleClick += keyPictureBox_DoubleClick;
this.k0308PictureBox.DoubleClick += keyPictureBox_DoubleClick;
this.k0309PictureBox.DoubleClick += keyPictureBox_DoubleClick;
this.k0310PictureBox.DoubleClick += keyPictureBox_DoubleClick;
this.k0311PictureBox.DoubleClick += keyPictureBox_DoubleClick;
this.k0312PictureBox.DoubleClick += keyPictureBox_DoubleClick;
this.k0313PictureBox.DoubleClick += keyPictureBox_DoubleClick;
this.k0401PictureBox.DoubleClick += keyPictureBox_DoubleClick;
this.k0402PictureBox.DoubleClick += keyPictureBox_DoubleClick;
this.k0403PictureBox.DoubleClick += keyPictureBox_DoubleClick;
this.k0404PictureBox.DoubleClick += keyPictureBox_DoubleClick;
this.k0405PictureBox.DoubleClick += keyPictureBox_DoubleClick;
this.k0406PictureBox.DoubleClick += keyPictureBox_DoubleClick;
this.k0407PictureBox.DoubleClick += keyPictureBox_DoubleClick;
this.k0408PictureBox.DoubleClick += keyPictureBox_DoubleClick;
this.k0409PictureBox.DoubleClick += keyPictureBox_DoubleClick;
this.k0410PictureBox.DoubleClick += keyPictureBox_DoubleClick;
this.k0411PictureBox.DoubleClick += keyPictureBox_DoubleClick;
this.k0412PictureBox.DoubleClick += keyPictureBox_DoubleClick;
this.k0413PictureBox.DoubleClick += keyPictureBox_DoubleClick;
this.k0501PictureBox.DoubleClick += keyPictureBox_DoubleClick;
this.k0502PictureBox.DoubleClick += keyPictureBox_DoubleClick;
this.k0503PictureBox.DoubleClick += keyPictureBox_DoubleClick;
this.k0504PictureBox.DoubleClick += keyPictureBox_DoubleClick;
this.k0505PictureBox.DoubleClick += keyPictureBox_DoubleClick;
this.k0506PictureBox.DoubleClick += keyPictureBox_DoubleClick;
this.k0507PictureBox.DoubleClick += keyPictureBox_DoubleClick;
this.k0508PictureBox.DoubleClick += keyPictureBox_DoubleClick;
this.k0509PictureBox.DoubleClick += keyPictureBox_DoubleClick;
this.k0510PictureBox.DoubleClick += keyPictureBox_DoubleClick;
this.k0511PictureBox.DoubleClick += keyPictureBox_DoubleClick;
}
#endregion
#region 폼 닫힌 경우 처리하기 - Form_FormClosed(sender, e)
/// <summary>
/// 폼 닫힌 경우 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void Form_FormClosed(object sender, FormClosedEventArgs e)
{
if(this.isPressedSHIFT)
{
keyPictureBox_Click(this.k0401PictureBox, EventArgs.Empty);
}
}
#endregion
#region 키 클릭시 처리하기 - keyPictureBox_Click(sender, e)
/// <summary>
/// 키 클릭시 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void keyPictureBox_Click(object sender, EventArgs e)
{
PictureBox keyPictureBox = sender as PictureBox;
if(keyPictureBox == null)
{
return;
}
#region 1행
if(keyPictureBox == this.k0101PictureBox) // "~"
{
keybd_event((byte)Keys.Oem3, 0, 0 , 0);
keybd_event((byte)Keys.Oem3, 0, 0x02, 0);
}
if(keyPictureBox == this.k0102PictureBox) // "1"
{
keybd_event((byte)Keys.D1, 0, 0 , 0);
keybd_event((byte)Keys.D1, 0, 0x02, 0);
}
if(keyPictureBox == this.k0103PictureBox) // "2"
{
keybd_event((byte)Keys.D2, 0, 0 , 0);
keybd_event((byte)Keys.D2, 0, 0x02, 0);
}
if(keyPictureBox == this.k0104PictureBox) // "3"
{
keybd_event((byte)Keys.D3, 0, 0 , 0);
keybd_event((byte)Keys.D3, 0, 0x02, 0);
}
if(keyPictureBox == this.k0105PictureBox) // "4"
{
keybd_event((byte)Keys.D4, 0, 0 , 0);
keybd_event((byte)Keys.D4, 0, 0x02, 0);
}
if(keyPictureBox == this.k0106PictureBox) // "5"
{
keybd_event((byte)Keys.D5, 0, 0 , 0);
keybd_event((byte)Keys.D5, 0, 0x02, 0);
}
if(keyPictureBox == this.k0107PictureBox) // "6"
{
keybd_event((byte)Keys.D6, 0, 0 , 0);
keybd_event((byte)Keys.D6, 0, 0x02, 0);
}
if(keyPictureBox == this.k0108PictureBox) // "7"
{
keybd_event((byte)Keys.D7, 0, 0 , 0);
keybd_event((byte)Keys.D7, 0, 0x02, 0);
}
if(keyPictureBox == this.k0109PictureBox) // "8"
{
keybd_event((byte)Keys.D8, 0, 0 , 0);
keybd_event((byte)Keys.D8, 0, 0x02, 0);
}
if(keyPictureBox == this.k0110PictureBox) // "9"
{
keybd_event((byte)Keys.D9, 0, 0 , 0);
keybd_event((byte)Keys.D9, 0, 0x02, 0);
}
if(keyPictureBox == this.k0111PictureBox) // "0"
{
keybd_event((byte)Keys.D0, 0, 0 , 0);
keybd_event((byte)Keys.D0, 0, 0x02, 0);
}
if(keyPictureBox == this.k0112PictureBox) // "-"
{
keybd_event((byte)Keys.OemMinus, 0, 0 , 0);
keybd_event((byte)Keys.OemMinus, 0, 0x02, 0);
}
if(keyPictureBox == this.k0113PictureBox) // "+"
{
keybd_event((byte)Keys.Oemplus, 0, 0 , 0);
keybd_event((byte)Keys.Oemplus, 0, 0x02, 0);
}
if(keyPictureBox == this.k0114PictureBox) // "Backspace"
{
keybd_event((byte)Keys.Back, 0, 0 , 0);
keybd_event((byte)Keys.Back, 0, 0x02, 0);
}
if(keyPictureBox == this.k0115PictureBox) // "Insert"
{
keybd_event((byte)Keys.Insert, 0, 0 , 0);
keybd_event((byte)Keys.Insert, 0, 0x02, 0);
}
if(keyPictureBox == this.k0116PictureBox) // "Home"
{
keybd_event((byte)Keys.Home, 0, 0 , 0);
keybd_event((byte)Keys.Home, 0, 0x02, 0);
}
if(keyPictureBox == this.k0117PictureBox) // "PgUp"
{
keybd_event((byte)Keys.PageUp, 0, 0 , 0);
keybd_event((byte)Keys.PageUp, 0, 0x02, 0);
}
#endregion
#region 2행
if(keyPictureBox == this.k0201PictureBox) // "Tab"
{
keybd_event((byte)Keys.Tab, 0, 0 , 0);
keybd_event((byte)Keys.Tab, 0, 0x02, 0);
}
if(keyPictureBox == this.k0202PictureBox) // "Q"
{
keybd_event((byte)Keys.Q, 0, 0 , 0);
keybd_event((byte)Keys.Q, 0, 0x02, 0);
}
if(keyPictureBox == this.k0203PictureBox) // "W"
{
keybd_event((byte)Keys.W, 0, 0 , 0);
keybd_event((byte)Keys.W, 0, 0x02, 0);
}
if(keyPictureBox == this.k0204PictureBox) // "E"
{
keybd_event((byte)Keys.E, 0, 0 , 0);
keybd_event((byte)Keys.E, 0, 0x02, 0);
}
if(keyPictureBox == this.k0205PictureBox) // "R"
{
keybd_event((byte)Keys.R, 0, 0 , 0);
keybd_event((byte)Keys.R, 0, 0x02, 0);
}
if(keyPictureBox == this.k0206PictureBox) // "T"
{
keybd_event((byte)Keys.T, 0, 0 , 0);
keybd_event((byte)Keys.T, 0, 0x02, 0);
}
if(keyPictureBox == this.k0207PictureBox) // "Y"
{
keybd_event((byte)Keys.Y, 0, 0 , 0);
keybd_event((byte)Keys.Y, 0, 0x02, 0);
}
if(keyPictureBox == this.k0208PictureBox) // "U"
{
keybd_event((byte)Keys.U, 0, 0 , 0);
keybd_event((byte)Keys.U, 0, 0x02, 0);
}
if(keyPictureBox == this.k0209PictureBox) // "I"
{
keybd_event((byte)Keys.I, 0, 0 , 0);
keybd_event((byte)Keys.I, 0, 0x02, 0);
}
if(keyPictureBox == this.k0210PictureBox) // "O"
{
keybd_event((byte)Keys.O, 0, 0 , 0);
keybd_event((byte)Keys.O, 0, 0x02, 0);
}
if(keyPictureBox == this.k0211PictureBox) // "P"
{
keybd_event((byte)Keys.P, 0, 0 , 0);
keybd_event((byte)Keys.P, 0, 0x02, 0);
}
if(keyPictureBox == this.k0212PictureBox) // "["
{
keybd_event((byte)Keys.Oem4, 0, 0 , 0);
keybd_event((byte)Keys.Oem4, 0, 0x02, 0);
}
if(keyPictureBox == this.k0213PictureBox) // "]"
{
keybd_event((byte)Keys.Oem6, 0, 0 , 0);
keybd_event((byte)Keys.Oem6, 0, 0x02, 0);
}
if(keyPictureBox == this.k0214PictureBox) // "\"
{
keybd_event((byte)Keys.Oem5, 0, 0 , 0);
keybd_event((byte)Keys.Oem5, 0, 0x02, 0);
}
if(keyPictureBox == this.k0215PictureBox) // "Delete"
{
keybd_event((byte)Keys.Delete, 0, 0 , 0);
keybd_event((byte)Keys.Delete, 0, 0x02, 0);
}
if(keyPictureBox == this.k0216PictureBox) // "End"
{
keybd_event((byte)Keys.End, 0, 0 , 0);
keybd_event((byte)Keys.End, 0, 0x02, 0);
}
if(keyPictureBox == this.k0217PictureBox) // "PgDn"
{
keybd_event((byte)Keys.PageDown, 0, 0 , 0);
keybd_event((byte)Keys.PageDown, 0, 0x02, 0);
}
#endregion
#region 3행
if(keyPictureBox == this.k0301PictureBox) // "Caps Lock"
{
Image image;
if(this.isPressedCAPSLOCK)
{
image = Properties.Resources.K0301;
}
else
{
image = Properties.Resources.K0301ON;
}
this.k0301PictureBox.Image = image;
this.isPressedCAPSLOCK = this.isPressedCAPSLOCK ^ true;
keybd_event((byte)Keys.CapsLock, 0, 0 , 0);
keybd_event((byte)Keys.CapsLock, 0, 0x02, 0);
}
if(keyPictureBox == this.k0302PictureBox) // "A"
{
keybd_event((byte)Keys.A, 0, 0 , 0);
keybd_event((byte)Keys.A, 0, 0x02, 0);
}
if(keyPictureBox == this.k0303PictureBox) // "S"
{
keybd_event((byte)Keys.S, 0, 0 , 0);
keybd_event((byte)Keys.S, 0, 0x02, 0);
}
if(keyPictureBox == this.k0304PictureBox) // "D"
{
keybd_event((byte)Keys.D, 0, 0 , 0);
keybd_event((byte)Keys.D, 0, 0x02, 0);
}
if(keyPictureBox == this.k0305PictureBox) // "F"
{
keybd_event((byte)Keys.F, 0, 0 , 0);
keybd_event((byte)Keys.F, 0, 0x02, 0);
}
if(keyPictureBox == this.k0306PictureBox) // "G"
{
keybd_event((byte)Keys.G, 0, 0 , 0);
keybd_event((byte)Keys.G, 0, 0x02, 0);
}
if(keyPictureBox == this.k0307PictureBox) // "H"
{
keybd_event((byte)Keys.H, 0, 0 , 0);
keybd_event((byte)Keys.H, 0, 0x02, 0);
}
if(keyPictureBox == this.k0308PictureBox) // "J"
{
keybd_event((byte)Keys.J, 0, 0 , 0);
keybd_event((byte)Keys.J, 0, 0x02, 0);
}
if(keyPictureBox == this.k0309PictureBox) // "K"
{
keybd_event((byte)Keys.K, 0, 0 , 0);
keybd_event((byte)Keys.K, 0, 0x02, 0);
}
if(keyPictureBox == this.k0310PictureBox) // "L"
{
keybd_event((byte)Keys.L, 0, 0 , 0);
keybd_event((byte)Keys.L, 0, 0x02, 0);
}
if(keyPictureBox == this.k0311PictureBox) // ";"
{
keybd_event((byte)Keys.OemSemicolon, 0, 0 , 0);
keybd_event((byte)Keys.OemSemicolon, 0, 0x02, 0);
}
if(keyPictureBox == this.k0312PictureBox) // "'"
{
keybd_event((byte)Keys.OemQuotes, 0, 0 , 0);
keybd_event((byte)Keys.OemQuotes, 0, 0x02, 0);
}
if(keyPictureBox == this.k0313PictureBox) // "Enter"
{
keybd_event((byte)Keys.Enter, 0, 0 , 0);
keybd_event((byte)Keys.Enter, 0, 0x02, 0);
}
#endregion
#region 4행
if(keyPictureBox == this.k0401PictureBox) // "Left Shift"
{
if(this.isPressedSHIFT == false)
{
this.isPressedSHIFT = true;
Image leftSHIFTImage = Properties.Resources.K0401ON;
Image rightSHIFTImage = Properties.Resources.K0412ON;
this.k0401PictureBox.Image = leftSHIFTImage;
this.k0412PictureBox.Image = rightSHIFTImage;
keybd_event((byte)Keys.LShiftKey, 0, 0, 0);
}
else
{
this.isPressedSHIFT = false;
Image leftSHIFTImage = Properties.Resources.K0401;
Image rightSHIFTImage = Properties.Resources.K0412;
this.k0401PictureBox.Image = leftSHIFTImage;
this.k0412PictureBox.Image = rightSHIFTImage;
keybd_event((byte)Keys.LShiftKey, 0, 0x02, 0);
}
}
if(keyPictureBox == this.k0402PictureBox) // "Z"
{
keybd_event((byte)Keys.Z, 0, 0 , 0);
keybd_event((byte)Keys.Z, 0, 0x02, 0);
}
if(keyPictureBox == this.k0403PictureBox) // "X"
{
keybd_event((byte)Keys.X, 0, 0 , 0);
keybd_event((byte)Keys.X, 0, 0x02, 0);
}
if(keyPictureBox == this.k0404PictureBox) // "C"
{
keybd_event((byte)Keys.C, 0, 0, 0);
keybd_event((byte)Keys.C, 0, 0x02, 0);
}
if(keyPictureBox == this.k0405PictureBox) // "V"
{
keybd_event((byte)Keys.V, 0, 0, 0);
keybd_event((byte)Keys.V, 0, 0x02, 0);
}
if(keyPictureBox == this.k0406PictureBox) // "B"
{
keybd_event((byte)Keys.B, 0, 0 , 0);
keybd_event((byte)Keys.B, 0, 0x02, 0);
}
if(keyPictureBox == this.k0407PictureBox) // "N"
{
keybd_event((byte)Keys.N, 0, 0 , 0);
keybd_event((byte)Keys.N, 0, 0x02, 0);
}
if(keyPictureBox == this.k0408PictureBox) // "M"
{
keybd_event((byte)Keys.M, 0, 0 , 0);
keybd_event((byte)Keys.M, 0, 0x02, 0);
}
if(keyPictureBox == this.k0409PictureBox) // "<"
{
keybd_event((byte)Keys.Oemcomma, 0, 0 , 0);
keybd_event((byte)Keys.Oemcomma, 0, 0x02, 0);
}
if(keyPictureBox == this.k0410PictureBox) // ">"
{
keybd_event((byte)Keys.OemPeriod, 0, 0 , 0);
keybd_event((byte)Keys.OemPeriod, 0, 0x02, 0);
}
if(keyPictureBox == this.k0411PictureBox) // "?"
{
keybd_event((byte)Keys.OemQuestion, 0, 0, 0);
keybd_event((byte)Keys.OemQuestion, 0, 0x02, 0);
}
if(keyPictureBox == this.k0412PictureBox) // "Right Shift"
{
if(this.isPressedSHIFT == false)
{
this.isPressedSHIFT = true;
Image leftSHIFTImage = Properties.Resources.K0401ON;
Image rightSHIFTImage = Properties.Resources.K0412ON;
this.k0401PictureBox.Image = leftSHIFTImage;
this.k0412PictureBox.Image = rightSHIFTImage;
keybd_event((byte)Keys.RShiftKey, 0, 0, 0);
}
else
{
this.isPressedSHIFT = false;
Image leftSHIFTImage = Properties.Resources.K0401;
Image rightSHIFTImage = Properties.Resources.K0412;
this.k0401PictureBox.Image = leftSHIFTImage;
this.k0412PictureBox.Image = rightSHIFTImage;
keybd_event((byte)Keys.RShiftKey, 0, 0x02, 0);
}
}
if(keyPictureBox == this.k0413PictureBox) // "↑"
{
keybd_event((byte)Keys.Up, 0, 0 , 0);
keybd_event((byte)Keys.Up, 0, 0x02, 0);
}
#endregion
#region 5행
if(keyPictureBox == this.k0501PictureBox) // "Left Ctrl"
{
keybd_event((byte)Keys.LControlKey, 0, 0 , 0);
keybd_event((byte)Keys.LControlKey, 0, 0x02, 0);
}
if(keyPictureBox == this.k0502PictureBox) // "Left Alt"
{
keybd_event((byte)Keys.LMenu, 0, 0 , 0);
keybd_event((byte)Keys.LMenu, 0, 0x02, 0);
}
if(keyPictureBox == this.k0503PictureBox) // "한자"
{
keybd_event((byte)Keys.HanjaMode, 0, 0 , 0);
keybd_event((byte)Keys.HanjaMode, 0, 0x02, 0);
}
if(keyPictureBox == this.k0504PictureBox) // "Space"
{
keybd_event((byte)Keys.Space, 0, 0 , 0);
keybd_event((byte)Keys.Space, 0, 0x02, 0);
}
if(keyPictureBox == this.k0505PictureBox) // "한글/영문"
{
if(this.isHANGULMode == false)
{
this.isHANGULMode = true;
Image image = Properties.Resources.K0505HANGUL;
this.k0505PictureBox.Image = image;
}
else
{
this.isHANGULMode = false;
Image image = Properties.Resources.K0505ENGLISH;
this.k0505PictureBox.Image = image;
}
keybd_event((byte)Keys.HangulMode, 0, 0, 0);
}
if(keyPictureBox == this.k0506PictureBox) // "Right Alt"
{
keybd_event((byte)Keys.RMenu, 0, 0 , 0);
keybd_event((byte)Keys.RMenu, 0, 0x02, 0);
}
if(keyPictureBox == this.k0507PictureBox) // "Print"
{
keybd_event((byte)Keys.Apps, 0, 0 , 0);
keybd_event((byte)Keys.Apps, 0, 0x0002, 0);
}
if(keyPictureBox == this.k0508PictureBox) // "Right Ctrl"
{
keybd_event((byte)Keys.RControlKey, 0, 0 , 0);
keybd_event((byte)Keys.RControlKey, 0, 0x02, 0);
}
if(keyPictureBox == this.k0509PictureBox) // "←"
{
keybd_event((byte)Keys.Left, 0, 0 , 0);
keybd_event((byte)Keys.Left, 0, 0x02, 0);
}
if(keyPictureBox == this.k0510PictureBox) // "↓"
{
keybd_event((byte)Keys.Down, 0, 0 , 0);
keybd_event((byte)Keys.Down, 0, 0x02, 0);
}
if(keyPictureBox == this.k0511PictureBox) // "→"
{
keybd_event((byte)Keys.Right, 0, 0 , 0);
keybd_event((byte)Keys.Right, 0, 0x02, 0);
}
#endregion
PlaySound(sender);
}
#endregion
#region 키 더블 클릭시 처리하기 - keyPictureBox_DoubleClick(sender, e)
/// <summary>
/// 키 더블 클릭시 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void keyPictureBox_DoubleClick(object sender, EventArgs e)
{
keyPictureBox_Click(sender, EventArgs.Empty);
}
#endregion
//////////////////////////////////////////////////////////////////////////////// Function
#region 초기화 하기 - Initialize()
/// <summary>
/// 초기화 하기
/// </summary>
private void Initialize()
{
InitHook(this.virtualKeyboardPanel.Handle);
InstallHook();
}
#endregion
#region URI 구하기 - GetURI(filePath)
/// <summary>
/// URI 구하기
/// </summary>
/// <param name="filePath">파일 경로</param>
/// <returns>URI</returns>
private string GetURI(string filePath)
{
string applicationPath = Application.ExecutablePath;
int index = applicationPath.LastIndexOf(@"\");
applicationPath = applicationPath.Substring(0, index + 1);
string uri = applicationPath + filePath;
return uri;
}
#endregion
#region 사운드 재생하기 - PlaySound(filePath)
/// <summary>
/// 사운드 재생하기
/// </summary>
/// <param name="filePath">파일 경로</param>
private void PlaySound(string filePath)
{
SoundPlayer soundPlayer = new SoundPlayer();
soundPlayer.SoundLocation = GetURI(filePath);
soundPlayer.Play();
}
#endregion
#region 사운드 재생하기 - PlaySound(sender)
/// <summary>
/// 사운드 재생하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
private void PlaySound(object sender)
{
if(this.playSound)
{
PictureBox keyPictureBox = sender as PictureBox;
if(keyPictureBox == null)
{
return;
}
if(keyPictureBox == this.k0313PictureBox || keyPictureBox == this.k0401PictureBox ||
keyPictureBox == this.k0412PictureBox || keyPictureBox == this.k0504PictureBox ||
keyPictureBox == this.k0505PictureBox)
{
PlaySound("\\SOUND\\ShortFX.wav");
}
else
{
PlaySound("\\SOUND\\PlasticPot.wav");
}
}
}
#endregion
}
}