Search code examples
vb.netsendkeys

Visual Basic, what is the send key for this button?


here is a link to the button im referring to http://blog.laptopmag.com/wpress/wp-content/uploads/2012/07/ThinkPad-Keyboard-Face-Off_g4-T420.jpg

and the format im trying to find it coincides with this sort of formatting

{PGUP} = page up button
{LEFT} = left arrow
{ESC} = Escape

anybody know how you can send this as a sendkey? prefer to use this keyboard orientated method than sending right click to a screen as that causes its own issues with finding location through an emulator screen.

cheers to anyone who can help me, even if someone knows for certain it doesn't exist it means i can focus on something else instead :)

EDIT:

TL;DR

"+{F10} might be what you are looking for to bring up what is called the 'context menu' however if you are using a citrix (or similar) application then you might have issues with stuff not being in focus." :)

So what I have discovered on my own. there are several ways to send what I now know is the 'context menu' key. only one however was applicable to my situation. if I was able to write the code for sendkey then drarig29's answer might have worked but with the application I'm using (BluePrism I can not do it that way unfortunately) this was my solution (that doesn't work) "+{F10}" so '+' = SHIFT and F10 = F10 button. So shift F10 will work for people who are looking for a way to bring up the 'right-click menu' however this will not work for me, though im not sure why. I'm automating an application through citrix (emulator screen) and even though I make the mouse click on the screen and the use the sendKey "+{F10}" it does not make the context menu screen appear on the application. So I tried it manually and funny enough it also doesn't work in bringing up the context menu. Then I found out if you right click the area of the screen and the menu comes up then the send key works all of a sudden with no hitch. I think the problem is to do with some windows being in focus and some not but I have to work it out to be sure seeing as i sent a 'click' to the right area of the screen it should be in focus. but anyways cheers for the help :)


Solution

  • This is the context menu key. Its keycode is 93. To send a key using its keycode, use this :

    <DllImport("user32.dll")> _
    Private Shared Function keybd_event(bVk As Byte, bScan As Byte, dwFlags As UInteger, dwExtraInfo As Integer) As Boolean
    End Function
    
    Const KEYEVENTF_KEYDOWN = &H0
    Const KEYEVENTF_KEYUP = &H2
    
    Private Sub SendKey(KeyCode As Integer)
        keybd_event(CByte(KeyCode), 0, KEYEVENTF_KEYDOWN, 0)
        keybd_event(CByte(KeyCode), 0, KEYEVENTF_KEYUP, 0)
    End Sub
    

    You have to import System.Runtime.InteropServices (Imports System.Runtime.InteropServices).

    With this, to send context menu key, use SendKey(93).

    Edit :

    Declare Sub mouse_event Lib "user32" Alias "mouse_event" (ByVal dwFlags As Integer, ByVal dx As Integer, ByVal dy As Integer, ByVal cButtons As Integer, ByVal dwExtraInfo As Integer)
    
    Const MOUSEEVENTF_LEFTDOWN As Int32 = &H2
    Const MOUSEEVENTF_LEFTUP As Int32 = &H4
    Const MOUSEEVENTF_RIGHTDOWN As Int32 = &H8
    Const MOUSEEVENTF_RIGHTUP As Int32 = &H10
    
    Enum ClickType
        Left = 0
        Right = 1
    End Enum
    
    Sub SendClick(ClickType As ClickType, DestX As Integer, DestY As Integer)
        Select Case ClickType
            Case ClickType.Left
                Cursor.Position = New Point(DestX, DestY)
                mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
                mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
            Case ClickType.Right
                Cursor.Position = New Point(DestX, DestY)
                mouse_event(MOUSEEVENTF_RIGHTDOWN, 0, 0, 0, 0)
                mouse_event(MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0)
        End Select
    End Sub
    

    Use the previous method like that : SendClick(ClickType.Left, 20, 20)