Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Detect keyboard tab key in Borland C++

Posted on 2010-11-11
2
Medium Priority
?
1,923 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 1000 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

Enhanced Intelligibility Without Cable Clutter

Challenge: The ESA office in Brussels wanted a reliable audio conference system for video conferences. Their requirement - No participant must be left out from the conference and the audio quality must not be compromised.

Question has a verified solution.

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

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…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

971 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