/ Published in: C#
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
using System.Windows.Forms; namespace DistrictEditor.DataClasses { /// <summary> /// КлаÑÑ ÑоÑтоÑний клавиатуры /// </summary> public class Keyboard { /// <summary> /// Ðажата ли клавиша Ctrl /// </summary> public bool IsCtrlPressed { get; private set; } /// <summary> /// Ðажата ли клавиша Alt /// </summary> public bool IsAltPressed { get; private set; } /// <summary> /// КонÑтруктор. Принимает ÑкземплÑÑ€ формы, /// на которой нам необходимо мониторить Ð½Ð°Ð¶Ð°Ñ‚Ð¸Ñ /// </summary> /// <param name="form">ÐкземплÑÑ€ формы</param> public Keyboard(Form form) { if (form != null) { form.KeyDown += FormKeyDown; form.KeyUp += FormKeyUp; } } /// <summary> /// ВызываетÑÑ Ð¿Ñ€Ð¸ отпуÑкании клавиши /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void FormKeyUp(object sender, KeyEventArgs e) { IsCtrlPressed = IsCtrlPressed ? false : IsCtrlPressed; IsAltPressed = IsAltPressed ? false: IsAltPressed; } /// <summary> /// ВызываетÑÑ Ð¿Ñ€Ð¸ нажатии клавиши /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void FormKeyDown(object sender, KeyEventArgs e) { IsCtrlPressed = e.Control; IsAltPressed = e.Alt; } } }