Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Sending ALT+key with Delphi is not working

646 views
Skip to first unread message

yontal

unread,
Dec 2, 2016, 12:07:16 AM12/2/16
to
Hi
im using delphi to send keyboard storkes to xHarbour, i could send CTRL+key I could send any other key into the xHarbour program but somehow ALT is not working. This is the code I'm using in delphi.

What am I doing wrong



--------------
SendKey(ord('I'), true, false, false); //WORKS
SendKey(ord('I'), false, true, false); //NOT WORKING


----------------

procedure TfrmMainBrowse.SendKey(VK : Cardinal; Ctrl,Alt,Shift : Boolean);
var
MC,MA,MS : Boolean;
begin


{
Try to bring target window to foreground //im doing this before calling this procedure

ShowWindow(Wnd,SW_SHOW);
SetForegroundWindow(Wnd);
}
// Get current state of modifier keys
MC:=Hi(GetAsyncKeyState(VK_CONTROL))>127;
MA:=Hi(GetAsyncKeyState(VK_LMENU))>127;
MS:=Hi(GetAsyncKeyState(VK_SHIFT))>127;

// Press modifier keys if necessary (unless already pressed by real user)
if Ctrl<>MC then keybd_event(VK_CONTROL,0,Byte(MC)*KEYEVENTF_KEYUP,0);
if Alt<>MA then keybd_event(VK_LMENU,0,Byte(MA)*KEYEVENTF_KEYUP,0);
if Shift<>MS then keybd_event(VK_SHIFT,0,Byte(MS)*KEYEVENTF_KEYUP,0);

// Press key
keybd_event(VK,0,0,0);
keybd_event(VK,0,KEYEVENTF_KEYUP,0);

// Release modifier keys if necessary
if Ctrl<>MC then keybd_event(VK_CONTROL,0,Byte(Ctrl)*KEYEVENTF_KEYUP,0);
if Alt<>MA then keybd_event(VK_LMENU,0,Byte(Alt)*KEYEVENTF_KEYUP,0);
if Shift<>MS then keybd_event(VK_SHIFT,0,Byte(Shift)*KEYEVENTF_KEYUP,0);
end;


Yon

dlzc

unread,
Dec 2, 2016, 3:05:49 PM12/2/16
to
Dear yontal:

On Thursday, December 1, 2016 at 10:07:16 PM UTC-7, yontal wrote:

> im using delphi to send keyboard storkes to
> xHarbour, i could send CTRL+key I could send
> any other key into the xHarbour program but
> somehow ALT is not working. This is the code
> I'm using in delphi.
>
> What am I doing wrong

Have you asked on a Delphi newsgroup?

What OS is running? What else is running, that might be intercepting ALT+key characters?

What does the receiving code look like in xHarbour? Do you have any keyboard traps set?

Can you push your commands to a transaction file "from" Delphi, and when xHarbour can get exclusive access to a pre-existing file, it performs the requested operation?

David A. Smith

yontal

unread,
Dec 3, 2016, 10:02:52 PM12/3/16
to
Running windows 7
I don't thing this is a Delphi issue if I have notepad.exe as the top program it is getting the ALT keys (ALT-F would open the file menu)

I would take a look at the xHarbour code however I dont this ALT is treated differently then lets say CNTRL

Im not sure what you mean with a "transaction file"

dlzc

unread,
Dec 4, 2016, 3:54:02 PM12/4/16
to
Dear yontal:

On Saturday, December 3, 2016 at 8:02:52 PM UTC-7, yontal wrote:
> On Friday, December 2, 2016 at 3:05:49 PM UTC-5, dlzc wrote:

reorganized your response, so it flows better with the questions asked.
...
> > Have you asked on a Delphi newsgroup?
>
> I don't thing this is a Delphi issue if I
> have notepad.exe as the top program it is
> getting the ALT keys (ALT-F would open the
> file menu).

OK.

> > What OS is running? What else is running,
> > that might be intercepting ALT+key
> > characters?
>
> Running windows 7

... and what about other programs running? Are you sure that you made the xHarbour executable window primary, when trying to transmit the alt key sequence to it?

https://support.microsoft.com/en-us/kb/126449

> > What does the receiving code look like in
> > xHarbour? Do you have any keyboard traps set?
>
> I would take a look at the xHarbour code however
> I dont this ALT is treated differently then lets
> say CNTRL

It would be if extended characters is not turned on when it is compiled.
#define HB_INKEY_EXTENDED

> > Can you push your commands to a transaction
> > file "from" Delphi, and when xHarbour can get
> > exclusive access to a pre-existing file, it
> > performs the requested operation?
>
> Im not sure what you mean with a "transaction file"

Delphi could check for the existence of a file "COMMAND.2XH". If it did not exist, the last command was completed. You could create this file, push in the instructions you want executed. Then close the file.

xHarbour could check for the existence of the file "COMMAND.2XH". If it didn't exist, continue waiting. If it does exist, can it obtain an exclusive lock on the file? If no, continue waiting. If yes, process the command, release the lock, delete the file "COMMAND.2XH", then return to wait.

This way xHarbour can run in the background, no other application can capture / steal its intended keystrokes, and xHarbour window never has to be "on top" to get the message.

David A. Smith
0 new messages