Detecting key status for shift, ctrl and alt 
Author Message
 Detecting key status for shift, ctrl and alt


the infinite reservoars of wisdom, and expelled:

Quote:
>I cant figure out how to check if the user is holding down one or more
>of the control, shift and alt keys. Can someone please help me? I
>trued the Keystat.VBX but that doesnt work on these keys, do I need a
>third-party VBX or can I do this in code?

Trap the keys in the _KeyDown event of the object / form (if you
set .KeyPreview to True for the Form, it will receive all key
strokes). The _KeyDown event has a flag for Ctrl, Alt and Shift
called Shift. You can find constants for the Shift flag in
CONSTANTS.TXT.

' This code traps the Ctrl key
Sub control_KeyDown (KeyValue As Integer, Shift As Integer, ....)
        If Shift = CTRL_MASK Then
                Msgbox "You pressed Ctrl"
        End If
End Sub

Jens
--
Everything I said are the opinions of someone else.
I just cut-and-pasted.

Jens Balchen jr.       http://www.*-*-*.com/ ~balchen



Sun, 12 Jul 1998 03:00:00 GMT  
 Detecting key status for shift, ctrl and alt
I cant figure out how to check if the user is holding down one or more
of the control, shift and alt keys. Can someone please help me? I
trued the Keystat.VBX but that doesnt work on these keys, do I need a
third-party VBX or can I do this in code?

If someone can help please post the code here, or preferably mail me.

Thanx

---------------------------------------------------------------
Frode Breimo

www: http://www.idb.hist.no/~frodeb
---------------------------------------------------------------



Sun, 12 Jul 1998 03:00:00 GMT  
 Detecting key status for shift, ctrl and alt


Quote:
>I cant figure out how to check if the user is holding down one or more
>of the control, shift and alt keys. Can someone please help me? I
>trued the Keystat.VBX but that doesnt work on these keys, do I need a
>third-party VBX or can I do this in code?

>If someone can help please post the code here, or preferably mail me.

>Thanx

>---------------------------------------------------------------
>Frode Breimo

>www: http://www.idb.hist.no/~frodeb
>---------------------------------------------------------------

This is easy to accomplish by creating a global variable
ie CtrlDown as boolean

Say that you want to do show a form if the user holds down
the ctrl and d to display a form called about...

Private Sub ListBox1_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case 17
        CtrlDown=True
Case 68
        'Show form about
        If CtrlDown = True Then
            CtrlDown = False
            about.Show
        End If
End Select
End Sub

______________________________________________________
Andy Brunner
Phone: (201) 216 3511
Fax:   (201) 216 3511
Address: S209 Castle Point
         Hoboken NJ 07030

http://attila.stevens-tech.edu/~abrunner/
______________________________________________________



Sun, 12 Jul 1998 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Block System Key like ALT+TAB, Ctrl+Alt+Del, Ctrl+Esc key

2. HELP: detecting left/right shift/ctrl/alt

3. Shift, ctrl and Alt keys in QuickBasic

4. Cancelling Shift, Ctrl, and Alt keys

5. Help ~~ How to trap function keys ?(Alt ,Ctrl ,Shift)

6. Disable Alt+Tab, Ctrl+Esc, Ctrl+Shift+Esc...

7. Simulating the left alt+shift and the right alt+shift in vb

8. how to Send the CTRL+SHIFT keys (no other key)

9. How to block ALT+TAB and CTRL+ALT+DEL key

10. How to block ALT+TAB and CTRL+ALT+DEL key

11. Disabling Keys: CTRL, ALT, ESC, Window key

12. disable keys like "key WIN", ctrl-ESC, ALT-TAB

 

 
Powered by phpBB® Forum Software