Answer the question
In order to leave comments, you need to log in
How to make a delay with an interval?
Tracking the hotkey pressed by the user. WndProc - monitors Windows messages (greater than 5 in 1 second). Problem: how to get rid of multiple clicks so that there is at least a delay or time interval when the SetPrc () method will be called? Otherwise, it turns out that you can call the method many times in 1 second. Is there any way to block the SetPrc() method via lock and Thread.Sleep() ?
protected override void WndProc(ref Message keyPressed)
{
if (keyPressed.Msg == 0x0312)
{
if (CanWork)
{
switch (keyPressed.WParam.ToInt32())
{
case 1: SetPrtSc(); break;
}
}
}
base.WndProc(ref keyPressed);
}
Answer the question
In order to leave comments, you need to log in
It will be nice to do this:
1) Install the System.Reactive package
2) Add:
...
private Subject<int> myHotkey = new Subject<int>();
public MainForm()
{
...
myHotkey
.AsObservable()
.Throttle(TimeSpan.FromSeconds(1))
.Subscribe(hotkeyid => MessageBox.Show("Нажата горячая клавиша с ID: " + hotkeyid));
}
...
protected override void WndProc(ref Message keyPressed)
{
...
switch (keyPressed.WParam.ToInt32())
{
case 1:
{
SetPrtSc();
myHotkey.OnNext(keyPressed.WParam.ToInt32());
}
break;
...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question