5

is there a way to Translate a KeyCode in that way ,which will work if i use it at Keys.Sendkey();

private void Manager_KeyDown(object sender, KeyEventArgs e)
{
      Keys.SendKey(e.KeyCode.toString());
}

i tried that way and it wont work ,so is there a way to do that dynamically.

Rosmarine Popcorn
  • 10,761
  • 11
  • 59
  • 89

3 Answers3

2

Well i don't know a better what but this ,you should capture all keys on KeyDown event and send them as String in that format from that web site.

http://msdn.microsoft.com/en-us/library/system.windows.forms.sendkeys.send.aspx

Dr. Rajesh Rolen
  • 14,029
  • 41
  • 106
  • 178
1

Keys is the enumeration and does not contain a SendKey method. You can however do something like this:

SendKeys.Send(Keys.A.ToString());

You can also send multiple keys by using string concatenation:

SendKeys.Send(Keys.A.ToString() + Keys.B.ToString());

Similary, this code works for me:

private void departmentList_KeyDown(object sender, KeyEventArgs e)
{
    Keys key = e.KeyCode;
    SendKeys.Send(key.ToString());
}

Also check out this question: SendKeys::Send, going berserk. What is your goal by doing this, if I might ask?

Community
  • 1
  • 1
Pete
  • 10,651
  • 9
  • 52
  • 74
  • 1
    using you're method wont work for Special Key's like Enter ,Escape etc. it work's only for random keys Letter and Number's. My goal is to send these Key's at a WebService than another Portion of Application will get these key's and Send the System where is being running by. – Rosmarine Popcorn Nov 11 '11 at 21:32
  • ToString() convert Number 1 to `D1` not `1` and this will sends `D` and `1` sequentially. – guan boshen Feb 15 '21 at 01:09
0

It works great!

    public string ToString(Keys key)
    {
        switch (key)
        {
            case Keys.Back:
                return "{BACKSPACE}";
            case Keys.Separator:
                return "{BREAK}";
            case Keys.CapsLock:
                return "{CAPSLOCK}";
            case Keys.Delete:
                return "{DELETE}";
            case Keys.Down:
                return "{DOWN}";
            case Keys.End:
                return "{END}";
            case Keys.Enter:
                return "{ENTER}";
            case Keys.Escape:
                return "{ESC}";
            case Keys.Help:
                return "{HELP}";
            case Keys.Home:
                return "{HOME}";
            case Keys.Insert:
                return "{INSERT}";
            case Keys.Left:
                return "{LEFT}";
            case Keys.NumLock:
                return "{NUMLOCK}";
            case Keys.PageDown:
                return "{PGDN}";
            case Keys.PageUp:
                return "{PGUP}";
            case Keys.PrintScreen:
                return "{PRTSC}";
            case Keys.Right:
                return "{RIGHT}";
            case Keys.Scroll:
                return "{SCROLLLOCK}";
            case Keys.Tab:
                return "{TAB}";
            case Keys.Up:
                return "{UP}";
            case Keys.F1:
                return "{F1}";
            case Keys.F2:
                return "{F2}";
            case Keys.F3:
                return "{F3}";
            case Keys.F4:
                return "{F4}";
            case Keys.F5:
                return "{F5}";
            case Keys.F6:
                return "{F6}";
            case Keys.F7:
                return "{F7}";
            case Keys.F8:
                return "{F8}";
            case Keys.F9:
                return "{F9}";
            case Keys.F10:
                return "{F10}";
            case Keys.F11:
                return "{F11}";
            case Keys.F12:
                return "{F12}";
            case Keys.F13:
                return "{F13}";
            case Keys.F14:
                return "{F14}";
            case Keys.F15:
                return "{F15}";
            case Keys.F16:
                return "{F16}";
            case Keys.Add:
                return "{ADD}";
            case Keys.Subtract:
                return "{SUBTRACT}";
            case Keys.Multiply:
                return "{MULTIPLY}";
            case Keys.Divide:
                return "{DIVIDE}";
            case Keys.ShiftKey:
                return "+";
            case Keys.ControlKey:
                return "^";
            case Keys.Alt:
                return "%";

        }
        return key.ToString();
    }

Enjoy...

MiMFa
  • 981
  • 11
  • 14