我想编一个组合键代替单独键位的程序。比如按下a和s等于按下q
思路大概有一个。但不知对不对。windows应该不支持同时的多键位输入。现在的所谓组合键是指一定时间内按下的键就自认为是组合键。
所以再编程的时候需要一个定时器来判断按下的键位是否属于组合键。
然后就是用call来制定组合键的功能是q。
可是我只有思路。。。新手。。。不知道该怎样下手。
求代码。
Option Explicit Private Declare Function GetKeyboardState Lib "user32" (pbKeyState As Byte) As Long Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer) Dim aKey(0 To 255) As Byte GetKeyboardState aKey(0) If MyKey(aKey(vbKeyA)) And MyKey(aKey(vbKeyS)) Then KeyCode = vbKeyQ 'Debug.Print "Form_KeyDown", KeyCode, Chr$(KeyCode), Hex$(aKey(vbKeyA)), Hex$(aKey(vbKeyS)), Hex$(aKey(vbKeyQ)) Debug.Print "Form_KeyDown", KeyCode, Chr$(KeyCode), MyKey(aKey(vbKeyA)), MyKey(aKey(vbKeyS)), MyKey(aKey(vbKeyQ)) End Sub Function MyKey(bKey As Byte) As Boolean MyKey = (bKey And &H80) End Function
Option Explicit Private Declare Function GetKeyboardState Lib "user32" (pbKeyState As Byte) As Long Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer) Dim aKey(0 To 255) As Byte GetKeyboardState aKey(0) If MyKey(aKey(vbKeyA)) And MyKey(aKey(vbKeyS)) Then KeyCode = vbKeyQ 'Debug.Print "Form_KeyDown", KeyCode, Chr$(KeyCode), Hex$(aKey(vbKeyA)), Hex$(aKey(vbKeyS)), Hex$(aKey(vbKeyQ)) Debug.Print "Form_KeyDown", KeyCode, Chr$(KeyCode), MyKey(aKey(vbKeyA)), MyKey(aKey(vbKeyS)), MyKey(aKey(vbKeyQ)) ' Debug.Print , MyKey(aKey(vbKeyUp)), MyKey(aKey(vbKeyDown)), MyKey(aKey(vbKeyLeft)), MyKey(aKey(vbKeyRight)) Debug.Print "State Shift:Ctrl:Alt", MyKey(aKey(vbKeyShift)), MyKey(aKey(vbKeyControl)), MyKey(aKey(vbKeyMenu)) End Sub Function MyKey(bKey As Byte) As Boolean MyKey = (bKey And &H80) End Function