You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
68 lines
2.0 KiB
68 lines
2.0 KiB
5 years ago
|
using System;
|
||
|
using System.Collections.Generic;
|
||
|
using System.Windows.Forms;
|
||
|
|
||
|
namespace NumpadMonitor
|
||
|
{
|
||
|
internal partial class KeyConfig : Form
|
||
|
{
|
||
|
private readonly List<KeyHandler> keyHandlers = new List<KeyHandler>();
|
||
|
private KeyHandler askedKey;
|
||
|
private readonly bool AlternativeKeySet;
|
||
|
|
||
|
public KeyConfig(bool alternativeKeyset)
|
||
|
{
|
||
|
InitializeComponent();
|
||
|
AlternativeKeySet = alternativeKeyset;
|
||
|
KeyInfo[] keyset = alternativeKeyset ? KeySet.Alternative : KeySet.Numpad;
|
||
|
foreach (KeyInfo key in keyset)
|
||
|
AddKeyHandler(key);
|
||
|
AskNextKey();
|
||
|
}
|
||
|
|
||
|
private void AddKeyHandler(KeyInfo key)
|
||
|
{
|
||
|
KeyHandler keyHandler = new KeyHandler(key, this);
|
||
|
keyHandler.Register();
|
||
|
keyHandlers.Add(keyHandler);
|
||
|
}
|
||
|
|
||
|
private void AskNextKey()
|
||
|
{
|
||
|
KeyHandler keyHandler = keyHandlers.Find(x => x.KeyInfo.KeyCode == IntPtr.Zero);
|
||
|
if (keyHandler == null)
|
||
|
{
|
||
|
KeyCodeReaderWriter.Write(keyHandlers);
|
||
|
DisposeElements();
|
||
|
Close();
|
||
|
return;
|
||
|
}
|
||
|
AskKey(keyHandler);
|
||
|
}
|
||
|
|
||
|
private void AskKey(KeyHandler keyHandler)
|
||
|
{
|
||
|
askedKey = keyHandler;
|
||
|
label_key.Text = AlternativeKeySet ? KeySet.AlternativeToNumpad(keyHandler.KeyInfo).ToString() : keyHandler.KeyInfo.ToString();
|
||
|
}
|
||
|
|
||
|
private void HandleHotkey(IntPtr LParam)
|
||
|
{
|
||
|
label_keyCode.Text = LParam.ToInt64().ToString();
|
||
|
askedKey.SetKeyCode(LParam);
|
||
|
AskNextKey();
|
||
|
}
|
||
|
|
||
|
protected override void WndProc(ref Message m)
|
||
|
{
|
||
|
if (m.Msg == Constants.WM_HOTKEY_MSG_ID)
|
||
|
HandleHotkey(m.LParam);
|
||
|
base.WndProc(ref m);
|
||
|
}
|
||
|
|
||
|
public void DisposeElements()
|
||
|
{
|
||
|
keyHandlers.ForEach(x => x.Unregiser());
|
||
|
}
|
||
|
}
|
||
|
}
|