|
-
Dec 14th, 2005, 02:07 PM
#1
Thread Starter
Addicted Member
Detect shift key
In vb6 how do i detect whether the shift key is being pressed? I have read something about vbShiftMask but i cant seem to implement it into my program.
-
Dec 14th, 2005, 02:10 PM
#2
Re: Detect shift key
You can use the KeyDown property of a textbox (or other controls)
VB Code:
Option Explicit
Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
If Shift = 1 Then Debug.Print "Shift " & Chr(KeyCode)
End Sub
-
Dec 14th, 2005, 02:10 PM
#3
Re: Detect shift key
You can't detect it because there is no event for it.
It is used along with other keys like "a" to "z"...
for example if you press shift then "a", then you can detect that shift was pressed also.
[Edit], UPS.... nevermind, it seems that I was wrog
-
Dec 14th, 2005, 02:14 PM
#4
Thread Starter
Addicted Member
Re: Detect shift key
dglienna's code worked fine.
How would I make it detect that it is not being pressed?
-
Dec 14th, 2005, 02:36 PM
#5
Re: Detect shift key
Shift will be 0 if it isn't being pressed.
-
Dec 14th, 2005, 02:51 PM
#6
Thread Starter
Addicted Member
Re: Detect shift key
look at this:
VB Code:
Private Sub form_KeyDown(KeyCode As Integer, shift As Integer)
If shift = 1 Then
engupper.Visible = True
englower.Visible = False
shiftcheck = False
Else
englower.Visible = True
engupper.Visible = False
End If
End Sub
when I let go of shift then "engupper" just remains hidden. Any suggestions?
-
Dec 14th, 2005, 03:16 PM
#7
Re: Detect shift key
 Originally Posted by ajames
look at this:
VB Code:
Private Sub form_KeyDown(KeyCode As Integer, shift As Integer)
If shift = 1 Then
engupper.Visible = True
englower.Visible = False
shiftcheck = False
Else
englower.Visible = True
engupper.Visible = False
End If
End Sub
when I let go of shift then "engupper" just remains hidden. Any suggestions?
I think the IF block should be in ELSE and vice-versa.
VB Code:
Private Sub form_KeyDown(KeyCode As Integer, shift As Integer)
If shift = 1 Then
englower.Visible = True
engupper.Visible = False
Else
engupper.Visible = True
englower.Visible = False
shiftcheck = False
End If
End Sub
-
Dec 14th, 2005, 03:27 PM
#8
Thread Starter
Addicted Member
Re: Detect shift key
It still refuses to switch back when I let go of shift, however, if I press another button it switches back
-
Dec 14th, 2005, 03:30 PM
#9
Re: Detect shift key
I think you should use the GetAsyncKeyState API instead of form events. That's more reliable.
Pradeep
-
Dec 14th, 2005, 03:32 PM
#10
Thread Starter
Addicted Member
Re: Detect shift key
What are they and how do i do them?
-
Dec 14th, 2005, 03:38 PM
#11
Re: Detect shift key
It's an API that returns the key state of any key at that time - whether it is pressed or not. Just search for "GetAsyncKeyState" in this forum and you would get a lot of examples.
Pradeep
-
Dec 14th, 2005, 03:43 PM
#12
Re: Detect shift key
Something like...
VB Code:
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Private Sub MyProcedure()
If GetAsyncKeyState(vbKeyShift) Then
'Shift key is pressed
Else
'shift is not pressed
End If
End Sub
Pradeep
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
|