FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Assign a button control to arrow key
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Assign a button control to arrow key
Posted: Mon Apr 02, 2007 07:58 AM
Jeff,

Ok, its working :-)

You have to modify Class TButton Method KeyDown() this way:
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:
#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
Posts: 933
Joined: Sun Oct 09, 2005 01:05 PM
Assign a button control to arrow key
Posted: Mon Apr 02, 2007 10:36 PM

Success :D

Thanks Antonio, it is now working.

Jeff

Thanks,

Jeff Barnes



(FWH 16.11, xHarbour 1.2.3, Bcc730)
Posts: 1
Joined: Thu Mar 09, 2006 07:51 PM
Assign a button control to arrow key
Posted: Sat Apr 07, 2007 01:54 PM
Jeff Barnes wrote:Thanks Antonio.

Continue the discussion