Solved

Arrow keys to act like Tab key and SHIFT Tab

Posted on 2004-08-20
5
1,242 Views
Last Modified: 2013-11-20
In my pretranslatemessage function how can I get the Right and Left arrow keys to act like the Tab key and SHIFT Tab key?
0
Comment
Question by:Koderiter
  • 3
5 Comments
 
LVL 44

Expert Comment

by:AndyAinscow
Comment Utility
   if(pMsg->message == WM_KEYDOWN)
      {
            if(pMsg->wParam == VK_RIGHT)
            {
                  NextDlgCtrl();
                  return true;  //prevent default behaviour
            }
            else if(pMsg->wParam == VK_LEFT)
            {
                  PrevDlgCtrl();
                  return true;  //prevent default behaviour
            }
0
 

Author Comment

by:Koderiter
Comment Utility
What is contained in the NextDlgCtrl() and PrevDlgCtrl() functions? these functions are not declared in my project.
0
 
LVL 44

Expert Comment

by:AndyAinscow
Comment Utility
from help

CDialog::NextDlgCtrl
void NextDlgCtrl( ) const;

Remarks

Moves the focus to the next control in the dialog box. If the focus is at the last control in the dialog box, it moves to the first control.

0
 
LVL 44

Assisted Solution

by:AndyAinscow
AndyAinscow earned 250 total points
Comment Utility
If it isn't CDialog based then

CWnd::GetNextDlgTabItem  
CWnd* GetNextDlgTabItem( CWnd* pWndCtl, BOOL bPrevious = FALSE ) const;

Return Value

Pointer to the previous (or next) control that has the WS_TABSTOP style, if the member function is successful.

The returned pointer may be temporary and should not be stored for later use.

Parameters

pWndCtl

Identifies the control to be used as the starting point for the search.

bPrevious

Specifies how the function is to search the dialog box. If TRUE, the function searches for the previous control in the dialog box; if FALSE, it searches for the next control.

Remarks

Retrieves a pointer to the first control that was created with the WS_TABSTOP style and that precedes (or follows) the specified control.



ie to move to next
GetNextDlgItem(GetFocus(), false)->SetFocus();//swap false for true to move to prev
0
 
LVL 9

Accepted Solution

by:
Priyesh earned 250 total points
Comment Utility
Try this, it modifies the right arrow to tab and left arrow to shift tab, then passes to the actual pretranslate for default processing.

BOOL CFormTestView::PreTranslateMessage(MSG* pMsg)
{
      if(pMsg->message == WM_KEYDOWN)
      {
            if(pMsg->wParam == VK_RIGHT)
                  pMsg->wParam = VK_TAB ;
            else if(pMsg->wParam == VK_LEFT)
            {
                  pMsg->wParam = VK_TAB ;
                  //Set the shift key state
                  static BYTE bytKeyBuff[256] ;
                  GetKeyboardState((PBYTE)&bytKeyBuff) ;

                  //toggle shift key.
                  bytKeyBuff[VK_SHIFT] |= 0x80 ;//set the high bit to 1
                  SetKeyboardState((PBYTE)&bytKeyBuff) ;
                  //let the pretranslate do it's default thing
                  BOOL bReturn = CFormView::PreTranslateMessage(pMsg) ;
                  //toggle back to the original state
                  bytKeyBuff[VK_SHIFT] &= 0x7F ;//set the high bit to 0
                  SetKeyboardState((PBYTE)&bytKeyBuff) ;
                  return bReturn ;
            }
      }
      return CFormView::PreTranslateMessage(pMsg) ;
}

HTH
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Pressing cancel button with C# UI Automation 3 39
sumNumber challenge 16 98
has77  challenge 9 66
unix example issues 18 44
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

762 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

6 Experts available now in Live!

Get 1:1 Help Now