Click here to Skip to main content
15,922,315 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
This statement is not working for me... please help

when I type e.Control only e.KeyChr is coming nothing else... If use e.keychr=Chrw(key.alt) then again it gives error. cannot convert to chr.... please help...


VB
Public Class Form1

    <System.Runtime.InteropServices.DllImport("user32.dll")> _
    Private Shared Function GetAsyncKeyState(vKey As Keys) As Short
    End Function

    Private Sub Form1_KeyDown(sender As Object, e As KeyEventArgs) Handles Me.KeyDown

    End Sub

    Private Sub Form1_KeyPress(sender As Object, e As KeyPressEventArgs) Handles Me.KeyPress
        If e.Control And e.Alt And e.Shift Then

            If Convert.ToBoolean(GetAsyncKeyState(Keys.LShiftKey)) Then
                MsgBox("CTRL + ALT + LEFT SHIFT")
            ElseIf Convert.ToBoolean(GetAsyncKeyState(Keys.RShiftKey)) Then
                MsgBox("CTRL + ALT + RIGHT SHIFT")
            End If

        End If
    End Sub

End Class
Posted

On Load check if your KEYPREVIEW is set to true


VB
Private Sub XXXX_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.KeyPreview = True
End Sub


Then you just implement a keydown function
VB
Private Sub XXXX_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
        If e.KeyCode = Keys.Space Then
             MsgBox("Space button pressed")
        End If
End Sub


This works for me.
 
Share this answer
 
KeyPress won't give you all that info.. and simply isn't fired with only Specialkeys pressed
If you press "SHIF + A" KeyPress only gives you Keys.A

Better have a look at this one here ProcessCmdKey
MSDN Link[^]

http://social.msdn.microsoft.com/Forums/windows/en-US/6907cd57-4789-46ec-a5d5-e5b0975ff993/override-keypress-in-vbnet?forum=winforms[^]
 
Share this answer
 
Hi,

Try this :

select the form and enable the KeyPress event, thats it...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900