Solved

Detect keyboard tab key in Borland C++

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
A Computer Pen For PC For MS Lync 5 90
Broken Piece 5 136
Change Ricoh Aficio MP C4500 to default to scanning in color 7 178
Visual Studio 2013 and Eclipse Neon 6 37
Well I am not sure whether i deserve anything (credit or points) for this article, since I have not written the source code but discovered the same while browsing the net. I only wish to help EE users save some money and probably help the environmen…
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 use and create new code templates in NetBeans IDE 8.0 for Windows.

778 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