Results 1 to 10 of 10

Thread: [RESOLVED] Sendkeys: send LWin key

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2011
    Posts
    9

    Resolved [RESOLVED] Sendkeys: send LWin key

    Hello,
    I am trying to send the windows key (the one with the flag on) using sendkeys on the click of the button.

    This doesn't seem to be working:
    Code:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            SendKeys.Send(Keys.LWin)
        End Sub
    Any help would be much appreciated.

    Thanks in advance,

    Harry.

  2. #2
    Hyperactive Member DavesChillaxin's Avatar
    Join Date
    Mar 2011
    Location
    WNY
    Posts
    451

    Re: Sendkeys: send LWin key

    Well honestly I'm not to fond of the SendKeys approach. If all you're trying to accomplish is to show the start menu then I would suggest trying this.

    Code:
    Private Declare Sub keybd_event Lib "user32.dll" (ByVal bVk As IntPtr, ByVal bScan As IntPtr, ByVal dwFlags As IntPtr, ByVal dwExtraInfo As IntPtr)
    
    Private Const VK_STARTKEY = &H5B
    Private Const KEYEVENTF_KEYUP = &H2
    Private Const KEYEVENTF_KEYDOWN = &H0
    
    Private Sub Button1_Click( ByVal sender As System.Object,  ByVal e As System.EventArgs) Handles Button1.Click
       Call keybd_event(VK_STARTKEY, 0, KEYEVENTF_KEYDOWN , 0)
       Call keybd_event(VK_STARTKEY, 0, KEYEVENTF_KEYUP, 0)
    End Sub
    Either way I'm sure this code snippet can be easily modified to suit your needs.
    Please rate if my post was helpful!
    Per favore e grazie!




    Code Bank:
    Advanced Algebra Class *Update | True Gradient Label Control *Dev | A Smarter TextBox *Update | Register Global HotKey *Update
    Media Library Beta *Dev | Mouse Tracker (Available in VB.net and C#.net) *New | On-Screen Numpad (VB.net) *New

  3. #3

    Thread Starter
    New Member
    Join Date
    Dec 2011
    Posts
    9

    Re: Sendkeys: send LWin key

    Thank you!

    That works brilliantly.

    Just wondering, is there a way of getting the names and locations of each of the shortcuts on the Start Menu?


    Thanks,

    Harry

  4. #4
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: Sendkeys: send LWin key

    Possibly, but they wouldn't involve opening the menu first. Might I venture to suggest that you may be going all round the houses? What exactly are you wanting to do?

  5. #5
    PowerPoster
    Join Date
    Sep 2006
    Location
    Egypt
    Posts
    2,579

    Re: Sendkeys: send LWin key

    SendKeys send string, so this SendKeys.Send(Keys.LWin) actually will send the code of Keys.LWin.

    There is no special string to send Win key, but you can emulate by sending Ctrl+Esc, so try this
    Code:
    SendKeys.Send("^{Esc}")



  6. #6

    Thread Starter
    New Member
    Join Date
    Dec 2011
    Posts
    9

    Re: Sendkeys: send LWin key

    Thanks for all of your help.

  7. #7
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: Sendkeys: send LWin key

    Quote Originally Posted by 4x2y View Post
    SendKeys send string, so this SendKeys.Send(Keys.LWin) actually will send the code of Keys.LWin.

    There is no special string to send Win key, but you can emulate by sending Ctrl+Esc, so try this
    Code:
    SendKeys.Send("^{Esc}")
    Nah, that don't work for the same reason that the original code didn't. SendKeys sends direct to the current active application. The system won't respond because the system never receives the message. If it's on a button click event then, by definition it sends to the form on which the button is placed.

  8. #8
    PowerPoster
    Join Date
    Sep 2006
    Location
    Egypt
    Posts
    2,579

    Re: [RESOLVED] Sendkeys: send LWin key

    Nah, that don't work for the same reason that the original code didn't. SendKeys sends direct to the current active application. The system won't respond because the system never receives the message. If it's on a button click event then, by definition it sends to the form on which the button is placed
    No, it is work fine, when put a button on the form and click on it, the start menu popup.



  9. #9
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: [RESOLVED] Sendkeys: send LWin key

    Quote Originally Posted by 4x2y View Post
    No, it is work fine, when put a button on the form and click on it, the start menu popup.
    In every situation, regardless of the number of other applications running, or when another application is running "Always On Top"? Anyway, my mileage is completely different. Never works. The keybd_event method never not works so I'll be sticking with it.

  10. #10
    PowerPoster
    Join Date
    Sep 2006
    Location
    Egypt
    Posts
    2,579

    Re: [RESOLVED] Sendkeys: send LWin key

    Ctrl+Esc is a system wide hotkey, that is, it is always received by the system regardless of the number of applications running, or any of them is running "Always On Top".



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