Results 1 to 5 of 5

Thread: Detecting Control/Alt Keys

  1. #1

    Thread Starter
    Addicted Member Fat_N_Furry's Avatar
    Join Date
    Oct 2002
    Posts
    171

    Detecting Control/Alt Keys

    Can someone tell me why this code doesn't work for Control/Alt keys, and another way to detect them? If it's easier, you could just explain how to assign Control/Alt shortcuts (like Control-S in Word is save) becuase that's what I'm trying to accomplish.

    VB Code:
    1. Dim KeyAscii As String = Chr(e.KeyCode)


    Thanks in advance,
    Furry
    Eat long and prosper!
    If someone helps you, find someone you can help.
    If you still have time, click on the darn banner up there and help the forum!

  2. #2
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    Try this:

    Code:
        Private Sub TextBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown
            Dim keyVal As Char = Convert.ToChar(e.KeyCode)
            If e.Control And keyVal = "S" Then
                MessageBox.Show("Ctrl + S Pressed!")
            End If
        End Sub

  3. #3
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    this one would also work, I think

    if e.keyData = (keys.shift or keys.s) then 'shift + s pressed
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  4. #4
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    You can try this too

    VB Code:
    1. Private Sub TextBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown
    2.         If (Control.ModifierKeys And Keys.Control) = Keys.Control And e.KeyCode = Keys.S Then
    3.             MessageBox.Show("Pressed Control S")
    4.         End If
    5. End Sub
    Dont gain the world and lose your soul

  5. #5

    Thread Starter
    Addicted Member Fat_N_Furry's Avatar
    Join Date
    Oct 2002
    Posts
    171
    Dang! We have an abundance of help around here! Thanks, guys! I got it twice - or was that three times?

    Furry
    Eat long and prosper!
    If someone helps you, find someone you can help.
    If you still have time, click on the darn banner up there and help the forum!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width