PDA

Click to See Complete Forum and Search --> : Keydown problem


Inhumanoid
Nov 28th, 1999, 10:45 PM
What's wrong with this code ??
When the user presses shift and "+" or shift and "-" then I want something to happen.



Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)

If KeyCode = vbKeyF11 Then Call sscmdMenu_Click
If (Shift And vbShiftMask) > 0 Then
If KeyCode = vbKeyAdd Then
'Do something
End If
If KeyCode = vbKeySubtract Then
'Do something
End If
End If

End Sub

MartinLiss
Nov 29th, 1999, 11:17 AM
I usually use the built in constants like you do, but in this case I don't know what they are. However if you change vbkeyadd to 187 and vbKeySubtract to 109 it will work.

------------------
Marty

Blackthorne
Nov 29th, 1999, 11:40 AM
Easy way to find the key constant is to add this to your code.

debug.print (insert constant here)

This will print the constant value to the Immediate window.

------------------
Micheal Blackthorne

Inhumanoid
Nov 29th, 1999, 05:32 PM
MartinLiss, where did you find the dec's 187 and 109 ??
I want to know if there is a list in msdn or something ...

Cause 109 does'not seem to work...

B.T.W. that was pretty usefull information there, Blackthorne.. Anyways I could to the oposite of that (give a dec and get the constant) ??



[This message has been edited by Inhumanoid (edited 11-30-1999).]

MartinLiss
Nov 29th, 1999, 08:26 PM
I did what Blackthorne suggested and put Debug.Print KeyCode in the KeyDown event. 109 is what you get when you press the "-" key on the numeric key-pad. I thought that is the minus key you meant as opposed to the one on the main keyboard, because you said you wanted to trap Shift plus "-". On the main keyboard that's "_", not "-".

------------------
Marty