FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Assign a button control to arrow key
Posts: 933
Joined: Sun Oct 09, 2005 01:05 PM
Assign a button control to arrow key
Posted: Sat Mar 31, 2007 01:49 AM

Hi Everybody,

Is there a way to assign the function of a button to an arrow key so when the user uses the left or right arrow key it functions as if they clicked a button?

Thanks,

Jeff

Thanks,

Jeff Barnes



(FWH 16.11, xHarbour 1.2.3, Bcc730)
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Assign a button control to arrow key
Posted: Sat Mar 31, 2007 09:46 AM

Jeff,

If the button has the focus, then you may use oBtn:bKeyChar or oBtn:bKeyDown to detect those keystrokes and fire the button action

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: Sat Mar 31, 2007 08:15 PM

Antonio,

Actually I have 4 buttons that I would like to give the user the option to either click a button or an arrow key.

Ex. Left Arrow = BUTTON1
Right Arrow = BUTTON2
Up Arrow = BUTTON3
Down Arrow = BUTTON4

Jeff

Thanks,

Jeff Barnes



(FWH 16.11, xHarbour 1.2.3, Bcc730)
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Assign a button control to arrow key
Posted: Sat Mar 31, 2007 08:47 PM

Jeff,

Which control has the focus ? The keystrokes will go to the focused control

Any of the buttons ? Or other control ?

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: Sat Mar 31, 2007 09:11 PM

The area where the buttons are has the focus.

Jeff

Thanks,

Jeff Barnes



(FWH 16.11, xHarbour 1.2.3, Bcc730)
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Assign a button control to arrow key
Posted: Sat Mar 31, 2007 09:15 PM

Is that area a dialogbox ? a window ?

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: Sun Apr 01, 2007 12:10 AM

Sorry, I guess I should have mentioned that.

It's a Window.

I've tried:

SETKEY( K_UP,    { || MsgInfo( "UP pressed" ) } )
SETKEY( K_DOWN,  { || MsgInfo( "DOWN pressed" ) } ) 
SETKEY( K_LEFT,  { || MsgInfo( "LEFT pressed" ) } )
SETKEY( K_RIGHT, { || MsgInfo( "RIGHT pressed" ) } )

But with no luck ... basically nothing happens. (inkey.ch is in my code)

Jeff

Thanks,

Jeff Barnes



(FWH 16.11, xHarbour 1.2.3, Bcc730)
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Assign a button control to arrow key
Posted: Sun Apr 01, 2007 05:54 AM

Jeff,

When a window or a dialogbox has several controls, one of them has the focus. So you should assign bKeyDown or bKeyChar to all of them:

oBtn1:bKeyChar = { | nKey | MsgInfo( nKey ) }
oBtn2:bKeyChar = { | nKey | MsgInfo( nKey ) }
oBtn3:bKeyChar = { | nKey | MsgInfo( nKey ) }
oBtn4:bKeyChar = { | nKey | MsgInfo( nKey ) }

Instead of MsgInfo(), call a function where you check nKey and act accordingly

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: Sun Apr 01, 2007 12:06 PM

Antonio,

It seems to work with all the keys except the arrow keys :cry:

When I press an arrow key the focus moves to the next control.

Jeff

Thanks,

Jeff Barnes



(FWH 16.11, xHarbour 1.2.3, Bcc730)
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Assign a button control to arrow key
Posted: Sun Apr 01, 2007 02:58 PM

Jeff,

Use bKeyDown instead of bKeyChar and try it again

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: Sun Apr 01, 2007 03:01 PM

Antonio,

I've tried both ... and still the arrow keys just move to the next control.

Jeff

Thanks,

Jeff Barnes



(FWH 16.11, xHarbour 1.2.3, Bcc730)
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Assign a button control to arrow key
Posted: Sun Apr 01, 2007 03:11 PM

Jeff,

Please try this too besides the bKeyChar/bKeyDown:

oBtn1:nDlgCode = DLGC_WANTALLKEYS
oBtn2:nDlgCode = DLGC_WANTALLKEYS
oBtn3:nDlgCode = DLGC_WANTALLKEYS
oBtn4:nDlgCode = DLGC_WANTALLKEYS

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: Sun Apr 01, 2007 08:14 PM

Antonio,

Still no luck. Again, the focus is moved to the next control.

Jeff

Thanks,

Jeff Barnes



(FWH 16.11, xHarbour 1.2.3, Bcc730)
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Assign a button control to arrow key
Posted: Sun Apr 01, 2007 09:04 PM

Jeff,

We are going to build a sample and try to get it working

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: Sun Apr 01, 2007 11:24 PM

Thanks Antonio.

Thanks,

Jeff Barnes



(FWH 16.11, xHarbour 1.2.3, Bcc730)