简体   繁体   中英

How do I fix the error I have when trying to call the method that contain KeyEventArgs e as argument

Here is my code:

 public void Initialize()
    {
        //something here
        onKeyDown();
    }


    static void onKeyDown(KeyEventArgs e)
    {
        if (e.Key == Keys.H)
        {
            //do stuff
        }
    }

and I get this error: There is no argument given that corresponds to the required formal parameter 'e' of 'Main.onKeyDown(KeyEventArgs)'.

EDIT: Working With RAGE Plugin Hook, a library for gta v mod development.

I'm not really sure why you shouldn't do it, I'll let smarter people describe it.

Anyway, there's a way to call an event this way:

public void Initialize()
{
   onKeyDown((KeyEventArgs)System.EventArgs.Empty)
}

I would comment it but not enough reputation :(

Cannot comment yet so posting as response.

You need to share what you are trying to do here. Why would you want to simulate a keypress? You could perhaps do something like this:

public void Initialize()
    {
        //something here
        //onKeyDown();
DoStuff();
    }


    static void onKeyDown(KeyEventArgs e)
    {
        if (e.Key == Keys.H)
        {
            DoStuff();
        }
    }

static void DoStuff(){
// DoStuff
}

To me it appears that you are trying to explicitly call an even handler which is not the purpose of event handlers. They are designed to be executed on if a certain user action or automated application action takes place.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM