|
-
May 1st, 2000, 08:34 PM
#1
Thread Starter
Hyperactive Member
How do I use two KeyCodes at the same time ?
For example, when the user is pressing F1 (KeyCode: &H70)
and F2 (KeyCode: &H71) a messagebox or something else
should appear. Note: this message-box should appear
when the user presses this two buttons at the same time!!!
If he only presses one button nothing should happen !!!!! :d
Thanks for some adive, Matt-D(eutschland) 
[Edited by Matt-D on 05-02-2000 at 09:36 AM]
[Edited by Matt-D on 05-02-2000 at 12:23 PM]
-
May 1st, 2000, 09:52 PM
#2
Hope this is what you need
Private Sub Form_KeyDown(KeyCode As Integer, _
Shift As Integer)
If KeyCode = 112 Then
MsgBox "F1"
ElseIf KeyCode = 113 Then
MsgBox "F2"
End If
-
May 1st, 2000, 10:14 PM
#3
Hyperactive Member
You can also use Select Case:
Code:
Private Sub Form_KeyDown(KeyCode As Integer, _
Shift As Integer)
Select Case KeyCode
Case 112
MsgBox "F1"
Case 113
MsgBox "F2"
End Select
End Sub
-
May 2nd, 2000, 01:02 AM
#4
Well, to check if both the keys are down, you can use GetKeyState api. Bit 15 of the returnvalue is 1 if the key is down, otherwise it is 0 (of course).
Code:
Option Explicit
Private Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Integer
Private Const VK_F1 = &H70
Private Const VK_F2 = &H71
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Dim retVal As Long
If KeyCode = vbKeyF1 Then
'check if F2 is also down
retVal = GetKeyState(VK_F2)
ElseIf KeyCode = vbKeyF2 Then
'check if F1 is also down
retVal = GetKeyState(VK_F1)
End If
If (retVal And &H4000) = &H4000 Then
MsgBox "Now"
End If
End Sub
I hope I used the correct hex value, but a quick test worked.
[Edited by Frans C on 05-02-2000 at 02:03 PM]
-
May 2nd, 2000, 01:34 AM
#5
Thread Starter
Hyperactive Member
Isn't there a way without using the API?
For this programm I use VB 3 and it doesn't work with it!
There must be a way to do it ....................................
Matt-D(eutschland)
-
May 2nd, 2000, 02:30 AM
#6
I don't know of another way, but it should work in VB3 as well. Or if you are using 16 bit windows version you can try to change "user32" in "user", but I am not sure about that.
-
May 2nd, 2000, 02:36 AM
#7
Addicted Member
Here is a way to do it without an API call. You might want to add a check for time interval between the KeyDown events because as this code stands, you can press the F1 and then wait as long as you want and then Press the F2 and trigger the 'Proper Key Combo Detected code.
I'd really suggest trying to get the API call working, but if you can't this might be an alternative you can use.
Also, I'd really recommend not using the F1 key in the combination since F1 is typically used to invoke help.
Hope this helps.
Code:
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Static multiKey As Integer
multiKey = multiKey + KeyCode
Select Case multiKey
Case 112 'F1
'Detect Duplicate F1 press
If multiKey = 224 Then
multiKey = 0
End If
Case 113 'F2
'Detect Duplicate F2 press
If multiKey = 226 Then
multiKey = 0
End If
Case 225 'F1 + F2
'Proper Key Combo Detected
'Your Code Here
MsgBox "F1 & F2 Pressed"
multiKey = 0
Case Else
multiKey = 0
End Select
End Sub
[Edited by jcouture100 on 05-02-2000 at 02:41 PM]
-
May 2nd, 2000, 03:07 PM
#8
Conquistador
it is a variable that keeps the data inside it, until it is changed even if the sub is not running
-
May 2nd, 2000, 09:37 PM
#9
Thread Starter
Hyperactive Member
-
May 4th, 2000, 06:31 PM
#10
Conquistador
-
May 4th, 2000, 06:46 PM
#11
Member
jcouture100 has given a good solution
but in the code whate he suplyed
i dont know why he is checking for multykey=224
if multykey=112 then only the control of execution comes inside that block.
so there no need to have those if conditions.
-
May 4th, 2000, 07:31 PM
#12
transcendental analytic
The api one for multiple keys is independent from any keydown events in your application, so this is good for gamedevelopers:
Code:
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Public Sub DoKeys()
If GetAsyncKeyState(vbKeyF1) and GetAsyncKeyState(vbKeyF2) Then blablabla then msgbox "HEhehe!"
End Sub
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
May 5th, 2000, 10:13 AM
#13
Conquistador
-
May 5th, 2000, 02:54 PM
#14
Thread Starter
Hyperactive Member
It's just for fun.
With this extra feature the user chnages the backcolor
and the font of a grid.
[i] Matt-D(eutschland)
-
May 6th, 2000, 01:14 PM
#15
Conquistador
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
|