Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Arrow keys to act like Tab key and SHIFT Tab

Posted on 2004-08-20
5
Medium Priority
?
1,334 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 1000 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 1000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

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…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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 video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

718 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