Solved

Detect keyboard tab key in Borland C++

Posted on 2010-11-11
2
1,643 Views
Last Modified: 2013-12-09
I have been trying to detect VK_TAB using OnKeyDown(TObject *Sender, WORD &Key, TShiftState Shift), however, i found that it can detect all keys on my keyboard but VK_TAB.
btw, i'm using Borland C++. Can anyone help please?
0
Comment
Question by:elvjac
2 Comments
 
LVL 25

Accepted Solution

by:
kode99 earned 250 total points
ID: 34125911
The problem is that the tab key message is being trapped and used before you get to the point of a OnKeyDown event in any control or form.  

The simplest way to get around this is to catch the event through the TApplication events by setting a OnMessage handler.  The TApplication message handler sees the events before they are trapped by forms and controls.

So in your main form setup add a line,

  Application->OnMessage = AppMessage;

and create a function,

void __fastcall TForm1::AppMessage(tagMSG &Msg, bool &Handled)
{
  if( Msg.message == WM_KEYDOWN)
  {
    if(Msg.wParam == VK_TAB)
    {
      < do stuff here with the tab keystroke as desired>
      Handled = true;     // this will stop the message here 
    }
  }
}

Open in new window


Keep two things in mind.  First this AppMessage function will be in the loop for all processing of your program so make sure you do not slow things down.  

Secondly you will probably want to also check what form and control has focus so you can handle the tab key for the situation.  If you set Handled to true the message will not be passed any further.

Check the help on the TApplication.  Its automatically created for CBuilder apps and has some very useful functionality.
0
 
LVL 16

Expert Comment

by:George Tokas
ID: 34127265
You can use:
 if(GetAsyncKeyState(VK_TAB) != 0 )
{
//
}
I mentioned that at:
http://www.experts-exchange.com/Programming/Editors_IDEs/C_CPP_CS/CPP_Builder/Q_21147788.html
You can use it inside IdleLoop function.

George Tokas.
0

Featured Post

Free Trending Threat Insights Every Day

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

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…
Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.

747 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

10 Experts available now in Live!

Get 1:1 Help Now