Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8573007
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T19:09:12+00:00 2026-06-11T19:09:12+00:00

Im building a form that will function like a keypad on a touch screen.

  • 0

Im building a form that will function like a keypad on a touch screen. The problem Im having at the moment is that when I person presses a button for example the ‘1’ button, it must add that char ‘1’ to an edit box, which displays the keys already pressed. Now the problem Im experiencing is that once a person presses a key, I can add the char to the string already displayed in the edit box, but the cursor goes to the front of the edit box, and does not appear at the back. I use the following code to add a char to the edit box:

edtPassword.text := edtPassword.text + key;

Now that just adds the char to the end of the edit box, but how do I move the cursor to the end of the edit box.

Plus I do also have a backspace button, what code would I use the erase the last char of the string in the edit box if you clicked it?

Im using Delphi XE2

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T19:09:13+00:00Added an answer on June 11, 2026 at 7:09 pm

    Disclaimer:

    I’m not answering the question as it is. I’m trying to propose a way I’ll rather follow when I’d need a virtual keyboard.

    1. What about ready made component ?

    I would suggest you to use the TTouchKeyboard component, which is a VCL component, representing a virtual keyboard. That said, you’re developing something, what is already a part of Delphi distributions. It’s a part of Delphi since version 2010, but I can’t say in which distributions.

    2. It looks ugly and I’ll rather make my own:

    When I’ve seen TTouchKeyboard component for the first time, I was hoping that allows owner drawing. Well, unfortunately doesn’t. In that case I’d try to simulate key strokes by myself rather than solve cases like this for another components you may soon or later use.

    2.1. How to simulate keystrokes in your own way ?

    The following code simulates keystrokes by using the SendInput function and it’s based on the code used by TTouchKeyboard component:

    type
      TKeyState = (ksDown, ksUp);
    
    function SendInputKey(AVirtualKey: Integer; AScanCode: Integer;
      AKeyState: TKeyState): Boolean;
    var
      Input: TInput;
    begin
      Input.Itype := INPUT_KEYBOARD;
      if (AVirtualKey = -1) and (AScanCode >= 0) then
      begin
        Input.ki.wVk := MapVirtualKey(AScanCode, MAPVK_VSC_TO_VK);
        Input.ki.wScan := AScanCode;
      end
      else if (AVirtualKey >= 0) and (AScanCode = -1) then
      begin
        Input.ki.wVk := AVirtualKey;
        Input.ki.wScan := MapVirtualKey(AVirtualKey, MAPVK_VK_TO_VSC);
      end
      else if (AVirtualKey >= 0) and (AScanCode >= 0) then
      begin
        Input.ki.wVk := AVirtualKey;
        Input.ki.wScan := AScanCode;
      end;
      case AKeyState of
        ksDown: Input.ki.dwFlags := 0;
        ksUp: Input.ki.dwFlags := KEYEVENTF_KEYUP;
      end;
      Result := SendInput(1, Input, SizeOf(TInput)) = 1;
    end;
    

    And the usage of the above function. You can pass virtual key, scan code or both to this function. When you’ll be unsure with either of them, pass value of -1 and the key code will be additionally mapped by the MapVirtualKey function. The following example shows how to send a Backspace and then Shift + A:

    procedure TForm1.SpeedButton1Click(Sender: TObject);
    begin
      SendInputKey(VK_BACK, -1, ksDown);
      SendInputKey(VK_BACK, -1, ksUp);
      SendInputKey(VK_SHIFT, -1, ksDown);
      SendInputKey(Ord('A'), -1, ksDown);
      SendInputKey(Ord('A'), -1, ksUp);
      SendInputKey(VK_SHIFT, -1, ksUp);
    end;
    

    2.2. How to simulate keystrokes in a forbidden way ?

    You may also go against the reference and use the SendKey from Vcl.Touch.Keyboard unit. In the reference is stated that the SendKey is used internally and shouldn’t be called but it’s visible outside of the unit and if you’re bold enough you can use it like this:

    uses
      Vcl.Touch.Keyboard, Vcl.Touch.KeyboardTypes;
    
    procedure TForm1.SpeedButton1Click(Sender: TObject);
    var
      KeyData: TKeyData;
    begin
      KeyData := VKey(VK_BACK, -1);
      SendKey(KeyData, ksDown);
      SendKey(KeyData, ksUp);
      KeyData := VKey(VK_SHIFT, -1);
      SendKey(KeyData, ksDown);
      KeyData := VKey(Ord('A'), -1);
      SendKey(KeyData, ksDown);
      SendKey(KeyData, ksUp);
      KeyData := VKey(VK_SHIFT, -1);
      SendKey(KeyData, ksUp);
    end;
    

    2.3. How to simulate keystrokes in a different view ?

    • How to send text to another application ?
    • How to send keys to another application ?
    • How to send keys without using SendMessage and PostMessage ?
    • How to programmatically simulate user input ?
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am building a function that will validate the values in a form. How
I'm building a login form composite component. The page that uses it will pass
I am building an html5 calculator that looks like <form onsubmit=return false oninput=o.value =
I'm building a login form that will validate the login against a database, then
I'm building a contact form that appears in a jQuery popup box. When you
I'm building a Windows Form that includes a combo box control, and I wanted
I'm currently building a web form using APEX that is losely modelled after a
I am building a C# windows form app that pings multiple computers by name,
Right now I'm building a simple form and I'm designing it so that if
I'm building a desktop (thick) Infopath 2010 form with code-behinds that need to set

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.