以编程方式按"Right Shift"键



我很难找到一种方法来以编程方式按下右移键。我需要一把上下键(按下/松开(。

我拥有的是:

SendKeys.Send("{RSHIFT}")

我知道这种转变就像:

SendKeys.Send("+")

我想这只是一个移位键,但我需要一个右移位键。

有人能帮我查一下这个密码吗?

使用键bd_event,您不需要窗口句柄

VB:

Public Class MyKeyPress
<DllImport("user32.dll", CharSet:=CharSet.Auto, CallingConvention:=CallingConvention.StdCall)>
Public Shared Sub keybd_event(ByVal bVk As UInteger, ByVal bScan As UInteger, ByVal dwFlags As UInteger, ByVal dwExtraInfo As UInteger)
End Sub

' To find other keycodes check bellow link
' http://www.kbdedit.com/manual/low_level_vk_list.html
Public Shared Sub Send(key As Keys)
Select Case key
Case Keys.A
keybd_event(&H41, 0, 0, 0)
Case Keys.Left
keybd_event(&H25, 0, 0, 0)
Case Keys.LShiftKey
keybd_event(&HA0, 0, 0, 0)
Case Keys.RShiftKey
keybd_event(&HA1, 0, 0, 0)
Case Else
Throw New NotImplementedException()
End Select
End Sub
End Class

C#:

public static class MyKeyPress
{
[DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
public static extern void keybd_event(uint bVk, uint bScan, uint dwFlags, uint dwExtraInfo);

// To get other key codes check bellow link
// http://www.kbdedit.com/manual/low_level_vk_list.html
public static void Send(Keys key)
{
switch (key)
{
case Keys.A:
keybd_event(0x41, 0, 0, 0);
break;
case Keys.Left:
keybd_event(0x25, 0, 0, 0);
break;
case Keys.LShiftKey:
keybd_event(0xA0, 0, 0, 0);
break;
case Keys.RShiftKey:
keybd_event(0xA1, 0, 0, 0);
break;
default: throw new NotImplementedException();
}
}
}

用法:

MyKeyPress.Send(Keys.LShiftKey)

在一些创造性的关键词组合后发现了这一点

它建立在发送密钥码的基础上:

Keys key = Keys.RShiftKey;//Right shift key  
SendMessage(Process.GetCurrentProcess().MainWindowHandle, WM_KEYDOWN, (int)key, 1);

我不知道这里的用例是什么,但要注意传递的窗口句柄参数:Process.GetCurrentProcess().MainWindowHandle

这会将击键发送给自己。如果您试图将其发送到另一个进程/程序,则需要传递该程序的窗口句柄。

最新更新