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.
		
		
		
		
		
			
		
			
				
					
					
						
							61 lines
						
					
					
						
							1.9 KiB
						
					
					
				
			
		
		
	
	
							61 lines
						
					
					
						
							1.9 KiB
						
					
					
				using System; | 
						|
using System.Collections.Generic; | 
						|
using System.Windows.Forms; | 
						|
 | 
						|
namespace NumpadMonitor | 
						|
{ | 
						|
    public partial class NumpadMonitorForm : Form | 
						|
    { | 
						|
        private readonly List<KeyHandler> keyHandlers = new List<KeyHandler>(); | 
						|
 | 
						|
        public delegate void NotifyKeyPressEvent(NumpadMonitorForm sender, KeyInfo key); | 
						|
 | 
						|
        public event NotifyKeyPressEvent KeyPressEvent; | 
						|
 | 
						|
        private readonly bool AlternativeKeySet; | 
						|
 | 
						|
        internal NumpadMonitorForm(List<KeyInfo> keyinfo, bool alternativeKeyset = false, bool visible = false) | 
						|
        { | 
						|
            AlternativeKeySet = alternativeKeyset; | 
						|
            InitializeComponent(); | 
						|
            Opacity = visible ? 100 : 0; | 
						|
            AddAllKeyHandlers(keyinfo); | 
						|
        } | 
						|
 | 
						|
        private void AddAllKeyHandlers(List<KeyInfo> keyinfo) | 
						|
        { | 
						|
            foreach (KeyInfo key in keyinfo) | 
						|
            { | 
						|
                AddKeyHandler(key); | 
						|
            } | 
						|
        } | 
						|
 | 
						|
        private void AddKeyHandler(KeyInfo key) | 
						|
        { | 
						|
            KeyHandler keyHandler = new KeyHandler(key, this); | 
						|
            keyHandler.Register(); | 
						|
            keyHandlers.Add(keyHandler); | 
						|
        } | 
						|
 | 
						|
        private void HandleHotkey(IntPtr LParam) | 
						|
        { | 
						|
            KeyHandler handler = keyHandlers.Find(x => x.KeyInfo.KeyCode.Equals(LParam)); | 
						|
            if (handler == null) return; | 
						|
            KeyInfo pressedKey = AlternativeKeySet ? KeySet.AlternativeToNumpad(handler.KeyInfo) : handler.KeyInfo; | 
						|
            KeyPressEvent?.Invoke(this, pressedKey); | 
						|
            label1.Text = pressedKey.ToString(); | 
						|
        } | 
						|
 | 
						|
        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()); | 
						|
        } | 
						|
    } | 
						|
} |