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
Jeff Barnes
(FWH 16.11, xHarbour 1.2.3, Bcc730)
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
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
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
Jeff,
Which control has the focus ? The keystrokes will go to the focused control
Any of the buttons ? Or other control ?
The area where the buttons are has the focus.
Jeff
Is that area a dialogbox ? a window ?
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
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
Antonio,
It seems to work with all the keys except the arrow keys
When I press an arrow key the focus moves to the next control.
Jeff
Jeff,
Use bKeyDown instead of bKeyChar and try it again
Antonio,
I've tried both ... and still the arrow keys just move to the next control.
Jeff
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
Antonio,
Still no luck. Again, the focus is moved to the next control.
Jeff
Jeff,
We are going to build a sample and try to get it working
Thanks Antonio.