Assign a button control to arrow key

Assign a button control to arrow key

Postby Jeff Barnes » Sat Mar 31, 2007 1: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
User avatar
Jeff Barnes
 
Posts: 929
Joined: Sun Oct 09, 2005 1:05 pm
Location: Ontario, Canada

Postby Antonio Linares » Sat Mar 31, 2007 9: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
User avatar
Antonio Linares
Site Admin
 
Posts: 42122
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby Jeff Barnes » Sat Mar 31, 2007 8: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
User avatar
Jeff Barnes
 
Posts: 929
Joined: Sun Oct 09, 2005 1:05 pm
Location: Ontario, Canada

Postby Antonio Linares » Sat Mar 31, 2007 8: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
User avatar
Antonio Linares
Site Admin
 
Posts: 42122
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby Jeff Barnes » Sat Mar 31, 2007 9:11 pm

The area where the buttons are has the focus.

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

Postby Antonio Linares » Sat Mar 31, 2007 9:15 pm

Is that area a dialogbox ? a window ?
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42122
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby Jeff Barnes » 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
User avatar
Jeff Barnes
 
Posts: 929
Joined: Sun Oct 09, 2005 1:05 pm
Location: Ontario, Canada

Postby Antonio Linares » Sun Apr 01, 2007 5: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
User avatar
Antonio Linares
Site Admin
 
Posts: 42122
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby Jeff Barnes » 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
User avatar
Jeff Barnes
 
Posts: 929
Joined: Sun Oct 09, 2005 1:05 pm
Location: Ontario, Canada

Postby Antonio Linares » Sun Apr 01, 2007 2:58 pm

Jeff,

Use bKeyDown instead of bKeyChar and try it again
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42122
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby Jeff Barnes » Sun Apr 01, 2007 3:01 pm

Antonio,

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



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

Postby Antonio Linares » Sun Apr 01, 2007 3: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
User avatar
Antonio Linares
Site Admin
 
Posts: 42122
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby Jeff Barnes » Sun Apr 01, 2007 8:14 pm

Antonio,

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


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

Postby Antonio Linares » Sun Apr 01, 2007 9:04 pm

Jeff,

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

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42122
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby Jeff Barnes » Sun Apr 01, 2007 11:24 pm

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

Next

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 34 guests