Assign a button control to arrow key

Postby Antonio Linares » Mon Apr 02, 2007 7:58 am

Jeff,

Ok, its working :-)

You have to modify Class TButton Method KeyDown() this way:
Code: Select all  Expand view
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  Expand view
#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
Antonio Linares
Site Admin
 
Posts: 42078
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby Jeff Barnes » Mon Apr 02, 2007 10:36 pm

Success :D

Thanks Antonio, it is now working.


Jeff
User avatar
Jeff Barnes
 
Posts: 929
Joined: Sun Oct 09, 2005 1:05 pm
Location: Ontario, Canada

Postby akis » Sat Apr 07, 2007 1:54 pm

Jeff Barnes wrote:Thanks Antonio.
akis
 
Posts: 1
Joined: Thu Mar 09, 2006 7:51 pm

Previous

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: cmsoft, Natter and 59 guests