Results 1 to 4 of 4

Thread: VB 2008 Code to run windows shortcut

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Dec 2009
    Location
    VietNam
    Posts
    81

    VB 2008 Code to run windows shortcut

    I intend to create a button to run a specified windows shortcut such as windows + E for explorer, Windows + D for Desktop. and i also want my windows form still to be active after running the shortcut.Any suggestion anyone?


    Thanks in advanced

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: VB 2008 Code to run windows shortcut

    I found this:

    vb Code:
    1. Public Class Form1
    2.  
    3.     Private Declare Sub keybd_event Lib "user32" _
    4.                       (ByVal bVk As Byte, _
    5.                        ByVal bScan As Byte, _
    6.                        ByVal dwFlags As Long, _
    7.                        ByVal dwExtraInfo As Long)
    8.  
    9.     Private Const VK_LWIN As Byte = &H5B
    10.     Private Const KEYEVENTF_KEYUP As Byte = &H2
    11.  
    12.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    13.         Dim VK_ACTION As Byte
    14.         Static index As Integer = 0
    15.         Select Case index Mod 7
    16.             Case 0 '&H45 is the hex character code
    17.                 'for the letter 'E' (ascii 69)
    18.                 VK_ACTION = &H45
    19.             Case 1 '&H46 is the hex character code
    20.                 'for the letter 'F' (ascii 70)
    21.                 VK_ACTION = &H46
    22.             Case 2 '&H4D is the hex character code
    23.                 'for the letter 'M' (ascii 77)
    24.                 VK_ACTION = &H4D
    25.             Case 3 '&H52 is the hex character code
    26.                 'for the letter 'R' (ascii 82)
    27.                 VK_ACTION = &H52
    28.             Case 4 '&H5B is the hex character code
    29.                 'for the start menu button
    30.                 VK_ACTION = &H5B
    31.             Case 5 '&H5E is the hex character code
    32.                 'for the caret chr (ascii 94)
    33.                 VK_ACTION = &H5E
    34.             Case 6 '&H70 is the hex character code
    35.                 'for the caret chr (ascii 112)
    36.                 VK_ACTION = &H70
    37.         End Select
    38.  
    39.         index += 1
    40.  
    41.         keybd_event(VK_LWIN, 0, 0, 0)
    42.         keybd_event(VK_ACTION, 0, 0, 0)
    43.         keybd_event(VK_LWIN, 0, KEYEVENTF_KEYUP, 0)
    44.  
    45.         Me.Focus()
    46.  
    47.     End Sub
    48.  
    49. End Class

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Dec 2009
    Location
    VietNam
    Posts
    81

    Re: VB 2008 Code to run windows shortcut

    Thanks a lot .I need some more reputation to rate you again

  4. #4
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: VB 2008 Code to run windows shortcut

    all you need to do is post 3 more times so your postcount >= 20, rate 10 other people, then you can rate me + i'll get 1 point

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