Solved

Arrow keys to act like Tab key and SHIFT Tab

Posted on 2004-08-20
5
1,254 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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
java ^ examples 8 66
Fibonacci challenge 11 123
mapBully challenge 6 135
Updating statistics with error notification email in SQL server 4 96
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
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.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

809 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