[英]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 + A , CTRL + 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 。
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 + A , CTRL + 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.