?
Solved

Sending keystroke from Delphi to another app

Posted on 1998-03-28
13
Medium Priority
?
408 Views
Last Modified: 2013-12-03
Generally, I'm using a Delphi app to update some files on remote computers. I need to be able to close out several applications that may be open. I'm able to identify if the apps in question are open, and close them, but several require additional effort. Namely, one always pops up a "Do you want to save your changes" button, which I need to respond to. The second is an app that also requires having a button clicked (or sending Alt+O).

My problem concerns passing a keyboard command (in my case, Alt+O) to the button in the other application. I can, I think, I identify the handle of the window I want to pass this to, but I'm just not getting the code right, because it isn't responding.  I have a feeling it has to do with using WM_SYSCHAR OR WM_SYSKEYDOWN but like I said before, I'm just not getting the code exact enough for it to work. Unfortunately, no examples I've seen have been specific enough to use.

Could someone give me a specific example. the previous question here does not provide me an answer because I've been down those roads, but apparently I'm doing something slightly wrong.
0
Comment
Question by:DARRAH
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 6
13 Comments
 
LVL 22

Accepted Solution

by:
nietod earned 400 total points
ID: 1412371
answer coming.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1412372
You probably should just send the WM_SYSCHAR message.  If that doesn;t work, you may need to try to send the WM_SYSKEYDOWN and WM_SYSKEYUP messages instead.  But most likely that is not necessary.

Try

SendMessage(WndHnd,WM_SYSCHAR,'O',0x20000000);


0
 

Author Comment

by:DARRAH
ID: 1412373
Please clarify: SendMessage requires a wParam, lParam which in Delphi is an integer value. For the O value, I can send the ASCII value of 79, (I think), but for the 0x20000000, I don't know what value to give to it. What does it stand for? And is there a value I can replace it with that will work in Delphi?
0
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 

Author Comment

by:DARRAH
ID: 1412374
Please clarify: SendMessage requires a wParam, lParam which in Delphi is an integer value. For the O value, I can send the ASCII value of 79, (I think), but for the 0x20000000, I don't know what value to give to it. What does it stand for? And is there a value I can replace it with that will work in Delphi?
0
 
LVL 22

Expert Comment

by:nietod
ID: 1412375
Yes, pass 79 for the 'O' and 536870912 for the lparam.  (That is 20000000 hex converted to decimal.)  If you don't wnat to hard-code the 79, you can convert a leter to an integer value in pascal.  I just don't rember how.  
0
 

Author Comment

by:DARRAH
ID: 1412376
I must be doing something wrong. On this particular dialog box, I have two TEdit fields to which I am able to send text. I'm getting their window handles and sending it using SENDMESSAGE(hwnd,WM_CHAR,wparam,lparam). That works. Now, I'm getting the Parent window handle, and I'm getting the TButton handle, and I know I have the two Tedit handles. Yet when I try SENDMESSAGE(HWnd,WM_SYSCHAR,79,536870912), with HWnd being any of the window handles I know, I'm getting no action. Actually, I'm getting a beep as if it doesn't recognize Alt+O as a valid keystroke. However, I know pressing Alt+O in that dialog pushes the button. I've tried sending it from each of the known window handles, and I've tried sending WM_SYSKEYDOWN followed by WM_SYSKEYUP from each of the known window handles. I'm truly stumped. I hope you have the patience and drive to give it another go.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1412377
You are trying the right things (different widnwo handles, different messages etc.)  There is, unfortunately, not much more that I can suggest.  

Do you have SPY++ or a similar tool?  You can use it to examine the messages that occur when you actually type an alt-o.  You can see what window gets the message and what the parameters are sent.  (For example, I left the OEM scan code as zero in the pararmeters because I did not know it and it really should not be needed, but perhaps it is.)
0
 
LVL 22

Expert Comment

by:nietod
ID: 1412378
I was fooling with spy and an app that takes alt-o to open a file from a dialog.

Unfortunately I can not copy the information from spy, so I'll type in the highlights.

when the alt key is pressed you get a SYSKEYDOWN wparam = 12h lparam = 68380001h.
when the o is pressed (with alt) you get a SYSKEYDOWN wparam = 4Fh lparam = 28180001h.
then you get a SYSCHAR wparam = 6Fh lparam= 28180001h.

there are no key-up messages that I can see (there are several 100 messages)  I suspect the dialog window is destroyed before the key upmessages are received.  So they must not matter (in this case).  This is an MFC application, not a OWL or VC.  But the key-up and key down messages will be the same, the messages in response will differ.  However, it would be pest if you could test on the actual application to see exactly which window gets the messages and what it does in response.



0
 

Author Comment

by:DARRAH
ID: 1412379
Using Winsight, this is what I get when I'm in the dialog and pressing Alt+O

* WinSight message trace Mon Mar 30 1998 05:27:53 *
03693.459 001657:00000798 "Edit1"  WM_SYSKEYDOWN (10404X) Dispatched   wp=00000012  lp=21380001 12h  18d  VK_MENU   Scan 38h  Alt  Extended  Down
03693.612 001658:00000798 "Edit1"  WM_SYSKEYDOWN (10404X) Dispatched   wp=0000004F  lp=20180001 4Fh  79d  VK_O   Scan 18h  Alt  Down
03693.612 001659:00000798 "Edit1"  WM_SYSCHAR (10604X) Dispatched   wp=0000004F  lp=20180001 4Fh  79d  'O'   Scan 18h  Alt  Down
03693.859 001660:000007A8 "OK"  WM_SYSKEYUP (10504X) Dispatched   wp=0000004F  lp=E0180001 4Fh  79d  VK_O   Scan 18h  Alt  Up

Edit1 is just the value of the control that I'm in when I pressed Alt+O.

My problem is converting the values I see here to a longint (or whatever value) that Sendmessage (or Delphi?) will use. As you can see, I'm close, but still lost.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1412380
Are you saying you don't know how to convert the Hex values to decimal?  Shame on you.  Weren't you paying attention in 8th grade...Using a Hex->decimal programmer's calculator I get.

12h = 18
21380001h = 55731145
4Fh = 79
20180001h = 538443777

0
 

Author Comment

by:DARRAH
ID: 1412381
Thanks for all your help and patience in pushing me through to the answer. And, by the way, I did sleep a lot in high school.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1412382
So it is working?  If the problem was just hex-dec stuff, I recommend you invest in a programmer's calculator.  They are usually under $10 and are just the right size to fit in you shirt pocket with your pens and rullers. :- )
0
 

Author Comment

by:DARRAH
ID: 1412383
Actually, I had a DOS version of Norton Utilities that had a hex converter in it. And, I don't do pocket pals. Thanks, again.
0

Featured Post

Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

770 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