Using System.forms.sendkeys.send

Posted on 2006-05-29
Last Modified: 2008-01-09
Hi, I am trying to make a keyboard to be used with a touchscreen.
I tried set forcus on a textbox and use system.form.sendkeys.send("A") and it worked. According to the .NET Framework reference it says...if to enter special characters dont not show i will have to use the codes.
For e.g. {BACKSPACE} will do the backspace keystroke.

However i am not sure how to use the code. I tried doing it ...... system.form.sendkeys.send("{BACKSPACE}") but it won't work... any ideas how can i get it to work with set forcus on a textbox?

thanks alot
Question by:jaxrpc
    LVL 44

    Expert Comment

    Hello jaxrpc,

    >> with set focus on a textbox
    worked for me like


    that was on a buttonclick did you use an other event?

    sharing what you know, learning what you don't

    Author Comment

    Hi thanks for replying.... what about capslock..... i tried"{CAPSLOCK}") and after that"A") it doesn't change "A" to "a" or it doesnt work this way?
    LVL 6

    Accepted Solution

    I found that using SendKeys with a {CAPSLOCK} and then immediately sending the rest of the keys worked.  However calling SendKeys from somewhere else in my code didn't take into account the fact I had called CAPSLOCK earlier.

    To get around this you can simulate CAPSLOCK being pressed with a pinvoke from "user32.dll" of SendInput.

    Details can be found at:

    It's a little convoluted but easy enough to make it work.

    Add a new class to your project and call it "NativeMethods".  Copy and paste the code from the website above (between Public Class NativeMethods and End Class) making sure to add a reference to System.Runtime.InteropServices at the top of the class' code.  (Imports System.Runtime.InteropServices)

    Then in your code you can add the "DoKeyBoard" method from that page somewhere on your form...

    Private Sub DoKeyBoard(ByVal flags As NativeMethods.KEYEVENTF, ByVal key As Keys)
        Dim input As New NativeMethods.INPUT
        Dim ki As New NativeMethods.KEYBDINPUT
        input.dwType = NativeMethods.InputType.Keyboard = ki = Convert.ToInt16(key) = 0 = 0 = flags = IntPtr.Zero
        Dim cbSize As Integer = Marshal.SizeOf(GetType(NativeMethods.INPUT))
        Dim result As Integer = NativeMethods.SendInput(1, input, cbSize)
        If result = 0 Then Debug.WriteLine(Marshal.GetLastWin32Error)
    End Sub

    Then to toggle CapsLock you can call the following two lines;

            DoKeyBoard(0, Keys.CapsLock)
            DoKeyBoard(NativeMethods.KEYEVENTF.KEYUP, Keys.CapsLock)

    (The two calls simulate the key being pressed and then released to switch the actual CAPSLOCK indicator light on in your system)



    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Join & Write a Comment

    Article by: Kraeven
    Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
    Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now