F
F
Fire Place2020-02-15 09:09:35
C++ / C#
Fire Place, 2020-02-15 09:09:35

Keystroke emulation (WinForms C#) with specific delay + random +-20ms delay?

Greetings to all, in fact, the question is in the header. I hope you can help (send a sample code).

In my program, the user presses his key in one form, after which, the code-number (int) of this button is written to a separate class, I need to implement in another class the function of constantly pressing this key (by code) with a certain delay and to it + - 20 ms through some random function to add or subtract.

Tell me how to implement it? I will be very grateful :)

  1. Form1
    public void NewForm_KeyDown(object sender, KeyEventArgs e)
            {
    
                if (e.KeyCode == Keys.PageDown)
                {
                    if (Storage.IsEnabled == true)
                    {
                        Storage.IsEnabled = false;
                        StatusOnOff.BackColor = Color.Red;
                    }
            
                }
    
    
                if (e.KeyCode == Keys.PageUp)
                {
    
                    if (Storage.IsEnabled == false)
                    {
                        Storage.IsEnabled = true;
                        StatusOnOff.BackColor = Color.Green;
                    }
    
                }
    
            }

  2. Form2
    private void ChooseKeyForm_KeyDown(object sender, KeyEventArgs e)
            {
                Storage.KeyData = e.KeyValue;
                this.Dispose();
            }

  3. A class that stores values ​​in order to pass them through forms
    internal class Storage
        {
            public static int KeyData { get; set; }
            public static bool IsEnabled { get; set; }
    
        }

  4. Class with a function (here you need to implement this function)
    class SpamKeyFunc
        {
            
        }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
twobomb, 2020-02-15
@Ld1948

https://docs.microsoft.com/en-us/dotnet/framework/...
https://docs.microsoft.com/en-us/dotnet/api/system...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question