SendKey and combo box

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • John Dio

    SendKey and combo box

    I am trying to create a on screen key board.

    I simply want to send a key (Simulate the keyboard) to a combo box using the Handle of the control.



    The below code is not working



    public const ushort WM_KEYDOWN = 0x0100;

    public const ushort WM_KEYUP = 0x0101;



    //Set the active window

    [DllImport("user 32.dll")]

    public static extern IntPtr SetActiveWindow (IntPtr hWnd);



    //sends a windows message to the specified window

    [DllImport("user 32.dll")]

    public static extern int SendMessage(Int Ptr hWnd, int Msg, uint wParam, int lParam);











    public void SendKey(ushort key, IntPtr hWnd)

    {

    SetActiveWindow (hWnd);

    // Control c = this.ActiveCont rol;

    // MessageBox.Show (c.Name.ToStrin g());

    SendMessage(hWn d, WM_KEYDOWN, key, 0);

    // c = this.ActiveCont rol;

    // MessageBox.Show (c.Name.ToStrin g());

    // SendMessage(hWn d, 0, key, 0);

    SendMessage(hWn d.Handle, WM_KEYUP, key, 0);

    }







    #endregion



    private void button3_Click(o bject sender, EventArgs e)

    {



    SendKey((int)Ke ys.A, comboBox1.Handl e);

    }





    I have tested SendKeys, Key_evnt and sendinput, they don't satisfy what is needed.



    Thanks,
  • Gaurav Vaish \(a.k.a. MasterGaurav\)

    #2
    Re: SendKey and combo box

    SendMessage(hWn d, WM_KEYDOWN, key, 0);
    SendMessage(hWn d.Handle, WM_KEYUP, key, 0);

    You'll have to create the corresponding lParam and wParam.
    Only "key-code" will not do.


    Posted to the window with the keyboard focus when a nonsystem key is pressed. A nonsystem key is a key that is pressed when the ALT key is not pressed.



    Try this out:
    SendMessage(hWn d, WM_KEYDOWN, key, 0x220001)
    SendMessage(hWn d, WM_KEYUP, key, 0xC0220001)

    Derived from:




    --
    Happy Hacking,
    Gaurav Vaish | http://dwt.sourceforge.net
    http://blogs.mastergaurav.com | http://eduzine.edujini-labs.com
    --------------------------------




    Comment

    Working...