毫无鸭梨。。。不要用楼上那个,因为只在软件本身有作用,把下面代码粘贴到代码窗口,然后加一个timer,下面以w a s d 分别代表上左下右为例
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Private Declare Function MapVirtualKey Lib "user32" Alias "MapVirtualKeyA" (ByVal wCode As Long, ByVal wMapType As Long) As Long
Private Declare Function VkKeyScan Lib "user32" Alias "VkKeyScanA" (ByVal cChar As Byte) As Integer
Private Declare Function SetKeyboardState Lib "user32" (lppbKeyState As Byte) As Long
Private Sub Putkey(z As Integer)
Call keybd_event(z, MapVirtualKey(z, 0), 0, 0)
Call keybd_event(z, MapVirtualKey(z, 0), 2, 0)
End Sub
Private Sub Form_Load()
Timer1.Interval = 50
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
'方向键(←): VK_LEFT (37)方向键(↑): VK_UP (38)方向键(→): VK_RIGHT (39)方向键(↓): VK_DOWN (40)这是方向键的ascii码
If GetAsyncKeyState(VkKeyScan(119)) = -32767 Then Putkey (38) '上
If GetAsyncKeyState(VkKeyScan(115)) = -32767 Then Putkey (40) '下
If GetAsyncKeyState(VkKeyScan(97)) = -32767 Then Putkey (37)'左
If GetAsyncKeyState(VkKeyScan(100)) = -32767 Then Putkey (39)'右
End Sub
''''''''''''''''''''''''''''''''''''''''''''''''注:119,115,97,100依次为w s a d 的ascii码,如果你不想用wasd,
'''''可以任意改,比如你想用t代表上就把119换成t的ascii码
ascii码对照表如图
vb可以用sendkeys
SendKeys {UP}可以发送向上方向键
SendKeys {DOWN}向下键
SendKeys {LEFT}向左键
SendKeys {RIGHT}向右键
楼主可以自己根据这个定制代码