Results 1 to 4 of 4

Thread: [RESOLVED] Some Case Keys do not work? (LControlKey,RControlKey,LMenu,RMenu)

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2016
    Posts
    5

    Resolved [RESOLVED] Some Case Keys do not work? (LControlKey,RControlKey,LMenu,RMenu)

    I've been having quite a rough time trying to figure out how to map hotkeys to left alt, right alt, left control and right control keys.
    First, I did this
    Code:
     Case Keys.ControlKey
                    My.Computer.Audio.Play(My.Resources.Who_are_you_2, AudioPlayMode.Background)
            End Select
    Code:
     Case Keys.Menu
                    My.Computer.Audio.Play(My.Resources.Who_are_you_2, AudioPlayMode.Background)
            End Select
    And they worked perfectly fine, HOWEVER I am only able to map the hotkeys to 2 basic keys. Control and Alt, meaning what the left and right alt keys COULD do, will only do 1 task, which isn't very satisfying for what I'm trying to create.

    After I had some trouble, I searched up "Key Enumerations System Keys"
    https://msdn.microsoft.com/en-us/lib...v=vs.110).aspx
    And sure enough, the keys I wanted existed, and upon discovering those keys, I looked at them in Visual Basic, and they too, existed. When I started tampering with it, to use left alt, right alt, etc, etc I only found out, that the keys did absolutely nothing, the tasks were not started.


    These are the codes I tried, all of them do absolutely nothing at all
    Code:
    Case Keys.RControlKey
                    My.Computer.Audio.Play(My.Resources.Who_are_you_2, AudioPlayMode.Background)
            End Select
    Code:
    Case Keys.LControlKey
                    My.Computer.Audio.Play(My.Resources.Who_are_you_2, AudioPlayMode.Background)
            End Select
    Code:
    Case Keys.LMenu
                    My.Computer.Audio.Play(My.Resources.Who_are_you_2, AudioPlayMode.Background)
            End Select
    Code:
    Case Keys.RMenu
                    My.Computer.Audio.Play(My.Resources.Who_are_you_2, AudioPlayMode.Background)
            End Select
    Thanks for helping me, I really appreciate it!

  2. #2

    Thread Starter
    New Member
    Join Date
    Nov 2016
    Posts
    5

    Re: Some Case Keys do not work? (LControlKey,RControlKey,LMenu,RMenu)

    bump

  3. #3

    Thread Starter
    New Member
    Join Date
    Nov 2016
    Posts
    5

    Re: Some Case Keys do not work? (LControlKey,RControlKey,LMenu,RMenu)

    Bump

  4. #4
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,582

    Re: Some Case Keys do not work? (LControlKey,RControlKey,LMenu,RMenu)

    I guess you can resort to using the GetKeyState API call to see which key caused the event.
    One thing to note is that the Alt keys are normally a state key. You press Alt, then another key. So pressing Alt multiple times will only report every other Alt key press.

    Code:
    Public Class Form1
    
      Private Declare Function GetKeyState _
           Lib "user32" (ByVal nVirtKey As Integer) As Integer
    
      Private Sub Form1_KeyDown(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
        Select Case e.KeyCode
          Case Keys.ShiftKey
            If GetKeyState(Keys.LShiftKey) < 0 Then
              Debug.Print("LShiftkey ")
            End If
            If GetKeyState(Keys.RShiftKey) < 0 Then
              Debug.Print("RShiftkey ")
            End If
    
          Case Keys.ControlKey
            If GetKeyState(Keys.LControlKey) < 0 Then
              Debug.Print("LControlkey ")
            End If
            If GetKeyState(Keys.RControlKey) < 0 Then
              Debug.Print("RControlkey ")
            End If
    
          Case Keys.Menu  'alt
            If GetKeyState(Keys.LMenu) < 0 Then
              Debug.Print("LAltkey ")
            End If
            If GetKeyState(Keys.RMenu) < 0 Then
              Debug.Print("RAltkey ")
            End If
    
          Case Else
            Debug.Print(e.KeyData.ToString)
        End Select
      End Sub
    End Class
    Last edited by passel; Nov 14th, 2016 at 05:39 AM.

Tags for this Thread

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