Solved

Use WM_CHAR instead of keybd_event ???

Posted on 1999-01-13
5
599 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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

This article surveys and compares options for encoding and decoding base64 data.  It includes source code in C++ as well as examples of how to use standard Windows API functions for these tasks. We'll look at the algorithms — how encoding and decodi…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
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…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

746 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

11 Experts available now in Live!

Get 1:1 Help Now