Solved

Use WM_CHAR instead of keybd_event ???

Posted on 1999-01-13
5
604 Views
Last Modified: 2013-12-03
I use keybd_event but if I call it to many time my program will exit with kernel32 error.

I think this happend because of leybd_event is to slow or something..

My program is in the background and I want it send a character from it to the activated window.

It's possible to use SendMessage and WM_CHAR and
use FoundWindow or something to find the
the activated windows and send a character to it from my program in the background ?


Please help me.
0
Comment
Question by:devfredde
  • 3
  • 2
5 Comments
 

Author Comment

by:devfredde
ID: 1418650
Edited text of question
0
 
LVL 22

Accepted Solution

by:
nietod earned 50 total points
ID: 1418651
>> It's possible to use SendMessage and WM_CHAR and
>> use FoundWindow or something to find the the activated windows
>> and send a character to it from my program in the background ?

Yes, you can use FindWindow() and SendMessage() to do this.  However, this may not work with all programs.  Some programs may "look at" the keyboard state in response to a  WM_CHAR (or WM_KEYxxxx) message.  If you just send the messages, the keyboard state will not be updated as if the key was pressed.  If you use keybd_event the state will be updated.

I would try to get keybd_event working before I try this approach.  It is likely to be easier and safer.

Did you try using a short sleep (Sleep()) after each event?
0
 

Author Comment

by:devfredde
ID: 1418652
>>Did you try using a short sleep (Sleep()) after each event?

No I haven't.
But I don't think it would help in this case.

You see, I send a chatacter over TCP/IP and use a server to read the incomming char.. and use Keybd_event to display it.

I have a text box, and every time I hit a key it will send the char.. over to the server and use Keybd_event to display it.
I use keybd_event twice, but the last one with the message key up.

keybd_event( 0x41,nCode,0,0 )
keybd_event( 0x41,nCode,KEYEVENTF_KEYUP,0,0 )

When I typed slowly it display all the char.. on the servers display but if I typed rapidly, some of the char.. will not be displayed or change place.

Exampel:

I typed "Hello Fredrik" rapidly
and the server displayed "Hell Ferdi"

To see if keybd_event is to slow. I use a loop on the client who send over 1000 of char... ( only A ). I only see one A and then it stoped and return a Kernel32 error.

Do you know what is wrong ?

 
0
 
LVL 22

Expert Comment

by:nietod
ID: 1418653
I suspect what is wrong is that you aren't given the process that receives the keyboard event time to process it.  keyboard and mouse events are placed in a single system queue until the applications with the focus can remove them.  If you are using all the processor time to post to that queue, and are not allowing the application with the focus to remove the events from the queue, then the events will get lost and/or the queue will fill.

Make sure your process is not using too much processor time.  It should be frequently calling GetMessage(), Sleep() or other that allows it to yield CPU time.  
0
 
LVL 22

Expert Comment

by:nietod
ID: 1418654
Is it working now?
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

This article describes a technique for converting RTF (Rich Text Format) data to HTML and provides C++ source that does it all in just a few lines of code. Although RTF is coming to be considered a "legacy" format, it is still in common use... po…
With most software applications trying to cater to multiple user needs nowadays, the focus is to make them as configurable as possible. For e.g., when creating Silverlight applications which will connect to WCF services, the service end point usuall…
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…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

920 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now