Solved

Arrow keys to act like Tab key and SHIFT Tab

Posted on 2004-08-20
5
1,277 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

738 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