Solved

Detect keyboard tab key in Borland C++

Posted on 2010-11-11
2
1,670 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

Superior storage. Superior surveillance.

WD Purple drives are built for 24/7, always-on, high-definition security systems. With support for up to 8 hard drives and 32 cameras, WD Purple drives are optimized for surveillance.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
hp designjet error 90:03 3 147
Ricoh Aficio 3510 default password 14 230
HP OfficeJet Pro 8600 Printer 4 74
Android studio getdrawable(int) is deprecated 4 36
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: …
It started not too long ago. It was at first annoying. My keystrokes seemed to be randomly generated, not the ones I typed on the keyboard. For some reason this only happened in certain applications (especially browsers such as IE11, Firefox and Chr…
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.

929 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