Simulating keyboard actions with delphi

Posted on 2008-11-03
Last Modified: 2013-11-05
Hi experts!

I have this problem: In a program I am working on, I have some custom Listbox with items. I can click on one item and the item will be selected... So I use the information of the item and process it. As soon I process this item, I want to simulate the action of doubleclick to go to the next item. Because this is a custom made listbox, I don't have access to indexitems. So I guess is a good idea to simulate the click (or double click) over the next item.

Is there a way to do this thru delphi 7?

Manuel Lopez (lopem)
Question by:lopem
    LVL 28

    Accepted Solution

    use mouse_event for mouse or keybd_event for keyboard
    see the following for examples and explanatiosn:
    LVL 44

    Expert Comment

    LVL 36

    Expert Comment

    by:Geert Gruwez
    you are developping a Delphi application
    and by stating  "Because this is a custom made listbox"
    what do you mean ?

    surely it is a Delphi component with events ?
    and if so it should have properties too
    maybe like FocusedIndex or ItemIndex
    i couldn't guess why these properties are unavailable
    but if so, it is a poor component
    how do you know what item was clicked or dblclicked ?

    there should be an event too : OnDblClick
    if nothing is assigned then the code is in the component ?

    and maybe you can subclass so you have acess to all properties (including private and protected) with

      TMagicListbox = class(TYourListbox)

    and when you use the TYourListbox cast it to the new type:
    and you will have all properties

    TMagicListbox(YourListbox).ItemIndex := 0; // for the first element

    TMagicListbox(YourListbox).ItemIndex := TMagicListbox(YourListbox).ItemIndex +1;
    to focus the next element

    LVL 28

    Expert Comment

    >>  you can subclass so you have acess to all properties (including private and protected)

    that is half true. with subclassing yuo get access to protected stuff only. not private :) in order to get access to private stuff, you need to declare the subclassing calss in teh same unit as the subclassed class. (I say stuff so to include: properties, members and methods)
    LVL 36

    Expert Comment

    by:Geert Gruwez
    i stand corrected about that stuff :D

    LVL 3

    Author Comment

    Hi, Geertz,

    I am using some components to build some chess application. They are very well written but some of the components have few peculiar behaviour, for instance, the custom Listbox I was talking about (a way to load a PGN file to a listbox. A PGN file is a collection of chess games in some format called Portable Game Notation).

    Of course teh component has OnDoubleclick, OnClick, etc. methods but they don't work as usual. For instance, if you want to see a chess game, there is not enough just to go to PGN1.Items[PGN1.ItemIndex]. For some reason you have to push the [enter]  key over the item selected or double click on it.  If you dont do this, you can't have access to a particular chess game. If I put the onDoubleClick method in my procedure, it always gives to me some sort of error saying the parameters are incorrect. Of course, I am doing something wrong but I couldn't figure out was wrong. To make things worst, the help file is in german  so I can actually understand some of it using altavista online translator.

    I found that the simple way to accomplish my task and to get rid of the error was just to insert some [enter] key thru programming or simulate a doubleclick over the item I selected.  I know this is not the best thing to do but I was really fed up with the error...

    When I read your remark I was thinking how it is possible to have some simple problems with these components? In any case, I actually solved my problems but I know I have to dig a little bit more around the chess components I am using.

    best regards and thanks for your comments.

    Manuel López (lopem)

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
    Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    how to add IIS SMTP to handle application/Scanner relays into office 365.

    761 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

    6 Experts available now in Live!

    Get 1:1 Help Now