I need to programmatically enter one character into a cell of a Delphi grid (in other application).
In order to do this manually, following steps are required:
- Press the F3 button.
- Press the right-arrow key 3 times.
- Press the space button.
- Type letter 'E' on the keyboard.
Press the right-arrow key.
// Press F3 button keybd_event(VK_F3, 0, 0, 0); // Press right arrow key 3 times keybd_event(VK_RIGHT, 0, 0, 0); keybd_event(VK_RIGHT, 0, 0, 0); keybd_event(VK_RIGHT, 0, 0, 0); // Press the space button keybd_event(VK_SPACE, 0, 0, 0); // Type letter E keybd_event(Ord('E'), 0, 0, 0); // Move to the right keybd_event(VK_RIGHT, 0, 0, 0);
But it doesn't work. When I run this code, nothing seems to happen.
How should I modify this code so that it actually simulates user input?
virtual keyboard
some time ago (and there will be many others). But to your problem, if you are targetingTStringGrid
, I think you can't do anything else than focus it and simulate your keystrokes (if I remember that right,TStringGrid
doesn't respond to any kind of message that would be able to set the text of a cell). – AdequacyWM_KEYDOWN
,WM_KEYUP
messages, but I'm not sure it will always work between two processes... – Adequacy