0

I asked a question earlier this day and that guy referred me to this topic: How can I convert 'System.Windows.Input.Key' to 'System.Windows.Forms.Keys'?

But since that topic is quite old, I assumed asking it here would be better. I got this code and I need it to convert me Keys, but I can't for the life of me understand what the code does.

Keys formsKey = ...;
Key wpfKey = ...;
wpfKey = KeyInterop.KeyFromVirtualKey((int)formsKey);
formsKey = (Keys)KeyInterop.VirtualKeyFromKey(wpfKey);

to be clear, I need to have a key conversion for this:

private void movement(object sender, System.Windows.Input.KeyEventArgs key)
    {
        if (wpfKey = Keys.Up)
        {
            x -= 20;
        } ...

So how exactly would that first code work in the second?

Community
  • 1
  • 1

1 Answers1

0

Is this what you mean?

private void movement(object sender, System.Windows.Input.KeyEventArgs key)
    {
        if ((Keys)KeyInterop.VirtualKeyFromKey(key) == Keys.Up)
        {
            x -= 20;
        } ...
Mojtaba Rezaeian
  • 8,268
  • 8
  • 31
  • 54