Answer the question
In order to leave comments, you need to log in
How to implement comparison in a condition?
In the code, I think it will be clear what's what and what I need. The only thing I will clarify is the Storage class (Storage.cs).
I use it because in my code there are 2 forms, one main, the second for receiving a key from the user (arbitrary), it is I who need to compare it in order to determine whether it is pressed or not.
I hope for your help :)
//form1
private void NewForm_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Storage.KeyData) //Когда клавиша отжата (Понимаю что e.KeyCode нельзя сравнить с e.KeyValue, как это обойти?)
//Чтобы когда чел ввел клавишу, на эту клавишу запускался таймер и через таймер повторялось нажатие клавиши
{
if (Storage.IsEnabled == false)
{
Storage.IsEnabled = true;
StatusOnOff.BackColor = Color.Green;
timer1.Start();
}
}
}
private void NewForm_KeyUp(object sender, KeyEventArgs e)
{
if (e.KeyCode == Storage.KeyData) //Когда клавиша отжата (Понимаю что e.KeyCode нельзя сравнить с e.KeyValue, как это обойти?)
//Чтобы когда чел ввел клавишу, на эту клавишу запускался таймер и через таймер повторялось нажатие клавиши
{
if (Storage.IsEnabled == true)
{
Storage.IsEnabled = false;
StatusOnOff.BackColor = Color.Red;
timer1.Stop();
}
}
}
private void timer1_Tick(object sender, EventArgs e)
{
int i= 0;
SendKeys.SendWait("{" + Storage.KeyStr + "}");
i--;
}
//form2
private void ChooseKeyForm_KeyDown(object sender, KeyEventArgs e)
{
Storage.KeyStr = e.KeyCode.ToString();
Storage.KeyData = e.KeyValue;
this.Dispose();
}
//storage.cs
internal class Storage {
public static string KeyStr { get; set; }
public static int KeyData { get; set; }
public static bool IsEnabled { get; set; }
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question