|
-
Jun 21st, 2000, 08:58 PM
#1
Thread Starter
Addicted Member
Is there a way to know if the user pressed the left or the right ctrl key on their keyboard. I need to be able to do different things depending on the ctrl left and ctrl right keys being pressed.
-
Jun 22nd, 2000, 03:14 AM
#2
Try this method. It uses DirectInput so you must include the Type Library. If you do not have the Library, I can send it to you.
Make a Form with a Timer called Timer1 and Insert the below code into the Form.
Code:
Dim dx7 As New DirectX7
Dim state As DIKEYBOARDSTATE
Dim iKey As Integer
Dim dinput As DirectInput
Dim keys(255) As String
Dim dev As DirectInputDevice
Private Sub Form_Load()
Timer1.Interval = 50
Set dinput = dx7.DirectInputCreate()
Set dev = dinput.CreateDevice("GUID_SysKeyboard")
dev.SetCommonDataFormat DIFORMAT_KEYBOARD
dev.Acquire
End Sub
Private Sub Form_Unload(Cancel As Integer)
dev.Unacquire
End Sub
Private Sub Timer1_Timer()
dev.GetDeviceStateKeyboard state
For iKey = 0 To 255
If state.Key(iKey) <> 0 Then
End If
Next
If state.Key(29) <> 0 Then Print "Left CTRL"
If state.Key(157) <> 0 Then Print "Right CTRL"
DoEvents
End Sub
-
Jun 22nd, 2000, 03:36 AM
#3
Thread Starter
Addicted Member
-
Jun 22nd, 2000, 09:48 AM
#4
PowerPoster
Another way to do it
Here is another way you can do it too.
Code:
Option Explicit
Private Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Integer
Private Const VK_LCONTROL = &HA2
Private Const VK_LSHIFT = &HA0
Private Const VK_RCONTROL = &HA3
Private Const VK_RSHIFT = &HA1
Private Sub Form_Load()
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
If GetKeyState(VK_LCONTROL) < 0 Then
MsgBox "Left Control Key is press"
ElseIf GetKeyState(VK_RCONTROL) < 0 Then
MsgBox "Right Control Key is press"
ElseIf GetKeyState(VK_LSHIFT) < 0 Then
MsgBox "Left Shift Key is press"
ElseIf GetKeyState(VK_RSHIFT) < 0 Then
MsgBox "Right Shift Key is press"
End If
End Sub
[Edited by Chris on 06-22-2000 at 10:50 PM]
-
Jun 23rd, 2000, 04:07 AM
#5
Using Chris's method is better because you do not need to include the Type Library or initialize any events.
However, the DirectInput can access 255 different keys which is better for gaming.
-
Aug 10th, 2000, 10:21 AM
#6
Member
Can u make this run from an executable that doesn't have the focus and a direct-x game is running on top of it?
Vince McMullin
Aka Vam, Vinny Mac
Its just that simple
-
Aug 10th, 2000, 10:32 AM
#7
Yes, the DirectInput method will work if your App doesn't have the focus. Chris's method will only work for Windows NT so I cannot test that out, but I'm pretty sure it will work as well.
-
Aug 10th, 2000, 10:44 AM
#8
Member
When the game is loaded it won't work, I'm guessing the game is resetting the dinput access.
But there is a cheat program out for the game that uses Hotkeys and it works fine, so I'm really baffeled by this.
The code works with any other application running on top of my program except for this game.
Could the cheat program have some Dinput hacks for this game? Or is there an actual way to do this?
I spent hours coding message stuff thinking this hotkey issue wasn't that big but now I find it is......... ?
Vince McMullin
Aka Vam, Vinny Mac
Its just that simple
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|