f



Sending ALT+key with Delphi is not working

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
  
0
yontal
12/2/2016 5:07:15 AM
comp.lang.xharbour 5470 articles. 0 followers. Post Follow

3 Replies
118 Views

Similar Articles

[PageSpeed] 29

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
0
dlzc
12/2/2016 8:05:48 PM
On Friday, December 2, 2016 at 3:05:49 PM UTC-5, dlzc wrote:
> 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

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"
0
yontal
12/4/2016 3:02:51 AM
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 seq=
uence 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=20

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 no=
t 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 di=
dn'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 captu=
re / steal its intended keystrokes, and xHarbour window never has to be "on=
 top" to get the message.

David A. Smith
0
dlzc
12/4/2016 8:54:00 PM
Reply: