Solved

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

Posted on 2008-10-18
7
1,180 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 500 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project (http://www.eclipse.org/sequoyah/) automates most of the tasks discussed in this article. You can even fin…
Here is a helpful source code for C++ Builder programmers that allows you to manage and manipulate HTML content from C++ code, while also handling HTML events like onclick, onmouseover, ... Some objects defined and used in this source include: …
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 NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.

717 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