Solved

Arrow keys to act like Tab key and SHIFT Tab

Posted on 2004-08-20
5
1,265 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
ID: 11854269
   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
ID: 11854393
What is contained in the NextDlgCtrl() and PrevDlgCtrl() functions? these functions are not declared in my project.
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 11854793
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
ID: 11854836
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
ID: 11865052
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Show shut-down message as Windows 8 shuts down. 9 100
notReplace  challenge 53 142
viewing source code from eclipse 13 110
wordcount challenge 11 134
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.

830 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