?
Solved

keybd_event not working with special characters like @, <, >, =, (, )

Posted on 2008-10-18
7
Medium Priority
?
1,184 Views
Last Modified: 2013-12-04
I had been trying some sequences on notepad, without problem but when i started to test  with special characters like @, <, >, =, (, ), they simply don't apper.
What can i do to fix the problem?
0
Comment
Question by:robballi
[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
  • 4
  • 3
7 Comments
 
LVL 3

Expert Comment

by:BTecho
ID: 22751311
Hi again :)

For @ symbol , simulate shift+2

    keybd_event(VK_SHIFT, 0, 0, 0);
    keybd_event(0x32, 0, 0, 0);
    keybd_event(0x32, 0, KEYEVENTF_KEYUP, 0);
    keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);

VK_2 is not declared in the list of virtual key codes so C++Builder will complain so you can put the hex value in instead.

another example for ) character , shift+0

    keybd_event(VK_SHIFT, 0, 0, 0);
    keybd_event(0x30, 0, 0, 0);
    keybd_event(0x30, 0, KEYEVENTF_KEYUP, 0);
    keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);

Here's a list of Virtual Key Codes
http://www.kbdedit.com/manual/low_level_vk_list.html
0
 
LVL 3

Expert Comment

by:BTecho
ID: 22751320
I got curious so I checked and the winuser.h file in the borland folder has the defined and mapped out the vk codes.

There I saw a comment
/*
 * VK_0 - VK_9 are the same as ASCII '0' - '9' (0x30 - 0x39)
 * 0x40 : unassigned
 * VK_A - VK_Z are the same as ASCII 'A' - 'Z' (0x41 - 0x5A)
 */

for 0 instead of 0x30 you could also put, for the ( character

    keybd_event(VK_SHIFT, 0, 0, 0);
    keybd_event('0', 0, 0, 0);
    keybd_event('0', 0, KEYEVENTF_KEYUP, 0);
    keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
0
 

Author Comment

by:robballi
ID: 22752572
Hi BTecho:

Nice to talk to you again.
I have to tell you about your kind solution i think only works for english keyboards, since form what i can see, your logic is that: Shift + 0 on english keyboard is ) and @ on english keyboard is Shift + 2. But in other languages it is not necesary the case!!
Besides i cannot still get:

for '< ' since Shift + ',' is <
i would suppose
    keybd_event(VK_SHIFT, 0, 0, 0);
    keybd_event(0x2C, 0, 0, 0);
    keybd_event(0x2C, 0, KEYEVENTF_KEYUP, 0);
    keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
unfortunatelly nothing happens!

for '>' since Shift + '.' is >
i would suppose
    keybd_event(VK_SHIFT, 0, 0, 0);
    keybd_event(0x2E, 0, 0, 0);
    keybd_event(0x2E, 0, KEYEVENTF_KEYUP, 0);
    keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
unfortunatelly nothing happens too!

for '='
i don't have any clue?

it seems that SendInput is superseding keybd_event, but i cannot find any specific piece of code of how to handle this on C++ Builder?

Thanks again.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Accepted Solution

by:
BTecho earned 2000 total points
ID: 22758650
That piece of code you posted doesn't work for me either.

Please try this piece of code to get the correct values of the keys. Needs two TEdit controls on the form...

//-On the OnKeyDown Event for Edit1----------------------------------------------------------------------
void __fastcall TForm1::Edit1KeyDown(TObject *Sender, WORD &Key,
      TShiftState Shift)
{
int keyint=Key;
Edit2->Text= IntToHex( keyint,2);
}
//---------------------------------------------------------------------------

The ",>"  key I found is  actually 0xBC . The Equals key is 0XBB without shift.
    keybd_event(0xBB, 0, 0, 0);
    keybd_event(0xBB, 0, KEYEVENTF_KEYUP, 0);

 I'm using an American/English based keyboard.
0
 

Author Comment

by:robballi
ID: 22760820
Dear BTecho:

Thanks to your advice it seems that these are the solutions:

for caracter == '<'
    keybd_event(VK_SHIFT, 0, 0, 0);
    keybd_event(0xBC, 0, 0, 0);
    keybd_event(0xBC, 0, KEYEVENTF_KEYUP, 0);
    keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);

for caracter == '>'
    keybd_event(VK_SHIFT, 0, 0, 0);
    keybd_event(0xBE, 0, 0, 0);
    keybd_event(0xBE, 0, KEYEVENTF_KEYUP, 0);
    keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);

for caracter == '='
    keybd_event(0xBB, 0, 0, 0);
    keybd_event(0xBB, 0, KEYEVENTF_KEYUP, 0);

Excelent advice BTecho
0
 

Author Closing Comment

by:robballi
ID: 31507516
Excelent advice from BTecho. Thanks a lot!!!
0
 
LVL 3

Expert Comment

by:BTecho
ID: 22764038
Very glad I could be of help :)
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

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…
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…
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.

743 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