Assign a button control to arrow key

User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Post by Antonio Linares »

Jeff,

Ok, its working :-)

You have to modify Class TButton Method KeyDown() this way:

Code: Select all

METHOD KeyDown( nKey, nFlags ) CLASS TButton

   ::oWnd:nLastKey := nKey

   do case
      case nKey == VK_UP .or. nKey == VK_LEFT
           if ::bKeyDown != nil
              Eval( ::bKeyDown, nkey, nFlags )
           else   
              ::oWnd:GoPrevCtrl( ::hWnd )
           endif   
           return 0

      case nKey == VK_DOWN .or. nKey == VK_RIGHT
           if ::bKeyDown != nil
              Eval( ::bKeyDown, nkey, nFlags )
           else   
              ::oWnd:GoNextCtrl( ::hWnd )
           endif   
           return 0

      case nKey == VK_RETURN
           if ::bKeyDown != nil
              Eval( ::bKeyDown, nkey, nFlags )
           else   
              PostMessage( ::hWnd, FM_CLICK )    // fire the button's action
           endif   
           return 0
   endcase

return Super:KeyDown( nKey, nFlags )
And here you have a working sample:

Code: Select all

#include "FiveWin.ch"

function Main()

   local oDlg, oBtn1, oBtn2, oBtn3, oBtn4

   DEFINE DIALOG oDlg TITLE "Test"
   
   @ 3,  2 BUTTON oBtn1 PROMPT "One" OF oDlg
   @ 3,  8 BUTTON oBtn2 PROMPT "Two" OF oDlg
   @ 3, 14 BUTTON oBtn3 PROMPT "Three" OF oDlg
   @ 3, 20 BUTTON oBtn4 PROMPT "Four" OF oDlg

   oBtn1:bKeyDown = { | nKey | MsgInfo( nKey ) }
   oBtn1:nDlgCode = DLGC_WANTALLKEYS
   oBtn2:bKeyDown = { | nKey | MsgInfo( nKey ) }
   oBtn2:nDlgCode = DLGC_WANTALLKEYS
   oBtn3:bKeyDown = { | nKey | MsgInfo( nKey ) }
   oBtn3:nDlgCode = DLGC_WANTALLKEYS
   oBtn4:bKeyDown = { | nKey | MsgInfo( nKey ) }
   oBtn4:nDlgCode = DLGC_WANTALLKEYS

   ACTIVATE DIALOG oDlg CENTERED

return nil
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Jeff Barnes
Posts: 912
Joined: Sun Oct 09, 2005 1:05 pm
Location: Ontario, Canada
Contact:

Post by Jeff Barnes »

Success :D

Thanks Antonio, it is now working.


Jeff
akis
Posts: 1
Joined: Thu Mar 09, 2006 7:51 pm

Post by akis »

Jeff Barnes wrote:Thanks Antonio.
Post Reply