简体   繁体   English

从CTRL +“东西”到带有代码示例的字符串

[英]From CTRL+“something” to a string with a code sample

    public virtual void Send(string keysToType, ActionListener actionListener)
    {
        if (heldKeys.Count > 0) keysToType = keysToType.ToLower();

        CapsLockOn = false;
        foreach (char c in keysToType)
        {
            short key = VkKeyScan(c);
            if (c.Equals('\r')) continue;

            if (ShiftKeyIsNeeded(key)) SendKeyDown((short) KeyboardInput.SpecialKeys.SHIFT, false);
            if (CtrlKeyIsNeeded(key)) SendKeyDown((short) KeyboardInput.SpecialKeys.CONTROL, false);
            if (AltKeyIsNeeded(key)) SendKeyDown((short) KeyboardInput.SpecialKeys.ALT, false);
            Press(key, false);
            if (ShiftKeyIsNeeded(key)) SendKeyUp((short) KeyboardInput.SpecialKeys.SHIFT, false);
            if (CtrlKeyIsNeeded(key)) SendKeyUp((short) KeyboardInput.SpecialKeys.CONTROL, false);
            if (AltKeyIsNeeded(key)) SendKeyUp((short) KeyboardInput.SpecialKeys.ALT, false);
        }

        actionListener.ActionPerformed(Action.WindowMessage);
    }

I need to send a list of keyboard shortcuts to that method 我需要发送该方法的键盘快捷键列表

CTRL + A , CTRL + End , etc. CTRL + ACTRL + End

But I don't know how to build such a string. 但是我不知道如何构建这样的字符串。

This far I wrote this: 到目前为止,我写道:

 string shortcuts;
 // shortcuts = "\CTRL + A" + "\CTRL + End";
 Send(shortcuts, myactionlistener)

Perhaps a 'normal' string is not the best format to do this? 也许“正常”字符串不是执行此操作的最佳格式?

If the string contains 'characters that need to be sent', perhaps a list of KeyEventArgs or some custom built data class could be sent to your Send method. 如果字符串包含“需要发送的字符”,则可能会将KeyEventArgs列表或一些自定义的内置数据类发送到您的Send方法。 Then you can loop over the list and execute one by one. 然后,您可以遍历列表并一个接一个地执行。 If you need combinations (like CTRL + K + CTRL + K (=toggle bookmark in Visual Studio)) you might need a composite . 如果您需要组合(例如CTRL + K + CTRL + K (在Visual Studio中=切换书签)),则可能需要一个Composite

Another option is to create your own DSL . 另一种选择是创建自己的DSL

Too late for Serge but for all the googlers out there... 对于Serge而言为时已晚,但对于那里的所有Google员工来说,...

Serge is referring to the Keyboard class in TestStack.White. Serge指的是TestStack.White中的Keyboard类。 The Send function can only be used to send strings literally to another window. Send函数只能用于从字面上将字符串发送到另一个窗口。 You cannot specify control keys here. 您不能在此处指定控制键。 They are just needed internally sometimes. 有时只是内部需要它们。 Eg Send("{") on my keyboard layout would internally translate to "AltKeyIsNeeded" and "7". 例如,键盘布局上的Send("{")会在内部转换为“ AltKeyIsNeeded”和“ 7”。

You can send keyboard shortcuts CTRL + A , CTRL + End like this: 您可以像这样发送键盘快捷键CTRL + ACTRL + End

myWindow.Keyboard.HoldKey(KeyboardInput.SpecialKeys.CONTROL);
myWindow.Keyboard.Enter("A");
myWindow.Keyboard.LeaveKey(KeyboardInput.SpecialKeys.CONTROL);

myWindow.Keyboard.HoldKey(KeyboardInput.SpecialKeys.CONTROL);
myWindow.Keyboard.HoldKey(KeyboardInput.SpecialKeys.END);
myWindow.Keyboard.LeaveKey(KeyboardInput.SpecialKeys.END);
myWindow.Keyboard.LeaveKey(KeyboardInput.SpecialKeys.CONTROL);

I've done something similar in an application, with the Windows key' shortcuts. 我已经使用Windows键的快捷键在应用程序中完成了类似的操作。 I'm used a WH_KEYBOARD_LL hook and when I've got a specific shortcut I call the method. 我使用了WH_KEYBOARD_LL hook ,当我有一个特定的快捷方式时,我调用了该方法。 Maybe this could help you. 也许这可以帮助您。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从任何地方捕获Ctrl +鼠标滚轮? - How to catch a Ctrl+ mousewheel from any place of code? 用于 CTRL+C 和 CTRL+V 手势的键绑定不起作用? - KeyBinding for gestures CTRL+C and CTRL+ V do not work? 获取在Ctrl + C操作后复制到变量的数据 - Get the data copied after Ctrl+ C operation to a variable 在UserControl中按CTRL + N键,将焦点对准AutoCompleteBox - Focus into AutoCompleteBox on CTRL+ N key pressed in UserControl 为什么按Ctrl +“+”会在TextBox中产生哔声? - Why does pressing Ctrl+“+” produce a beep in a TextBox? 如何在Win表单应用程序中检测两个热键,例如CTRL + C,CTRL + W - how to detect two hot key in win form app like CTRL +C , CTRL+ W 如何将Ctrl +(控制键和逗号)作为WPF菜单项的键盘快捷键? - How to assign Ctrl+, (control plus comma) as the keyboard shortcut to a WPF menu item? 当我们使用ctrl +鼠标左键单击wpf时如何取消选择devexpress数据网格行 - how to unselect a devexpress data grid row when we click with ctrl+ mouse left button wpf 代码示例:更新 <T> (sourceObject,targetObject,string []例外) - Code sample for: Update<T>(sourceObject, targetObject, string[] exceptions) Ctrl + PageUp / Down有点奇怪吗? - Ctrl+PageUp/Down does something weird?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM