如何将 KeyCode 翻译为在 Keys.SendKey 上工作

发布于 2024-12-15 06:53:47 字数 234 浏览 0 评论 0原文

有没有一种方法可以以这种方式翻译 KeyCode,如果我在 Keys.Sendkey(); 使用它,它就会起作用;

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

我试过这种方法,但行不通,所以有没有办法动态地做到这一点。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

断舍离 2024-12-22 06:53:47

好吧,我不知道更好的是什么,但是这个,您应该捕获 KeyDown 事件上的所有键,并将它们作为字符串以该格式从该网站发送。

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

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

无人问我粥可暖 2024-12-22 06:53:47

Keys 是枚举,不包含 SendKey 方法。但是,您可以执行以下操作:

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

您还可以使用字符串连接发送多个键:

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

类似地,此代码对我有用:

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

另请查看这个问题:SendKeys::发送,发狂。如果我可以问的话,你这样做的目的是什么?

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?

木森分化 2024-12-22 06:53:47

效果很好!

    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();
    }

享受...

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...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文