Simulating keyboard actions with delphi

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)
Who is Participating?
2266180Connect With a Mentor Commented:
use mouse_event for mouse or keybd_event for keyboard
see the following for examples and explanatiosn:
Geert GOracle dbaCommented:
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

>>  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)
Geert GOracle dbaCommented:
i stand corrected about that stuff :D

lopemAuthor Commented:
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)
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.