Select a buttonbar button by key

Select a buttonbar button by key

Postby Marco Turco » Sat Mar 29, 2008 2:21 pm

Hi,
unfortunately I still have a lot of customers that prefer to use the keyboard instead of the mouse (often in accounting application where the big work is a data-entry work).

In this sample www.softwarexp.co.uk/beta/screen2.png I have a office style buttonbar. Could be possibile to select a button of this buttonbar using the keyboard ?

Thanks.
Best Regards,

Marco Turco
SOFTWARE XP LLP
User avatar
Marco Turco
 
Posts: 858
Joined: Fri Oct 07, 2005 12:00 pm
Location: London

Postby Antonio Linares » Sat Mar 29, 2008 3:09 pm

Marco,

As you are using a pulldown menu, then you can define an accelerator for each menu item whose action matches with a specific buttonbar button action
regards, saludos

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

Postby Marco Turco » Sat Mar 29, 2008 3:15 pm

Yes, you are right
but - obviously - I have this problem when I use the buttonbar without menu. :roll:
Best Regards,

Marco Turco
SOFTWARE XP LLP
User avatar
Marco Turco
 
Posts: 858
Joined: Fri Oct 07, 2005 12:00 pm
Location: London

Postby Marco Turco » Sat Mar 29, 2008 7:11 pm

Solved. I used the function SetKey as turnaround.
Best Regards,

Marco Turco
SOFTWARE XP LLP
User avatar
Marco Turco
 
Posts: 858
Joined: Fri Oct 07, 2005 12:00 pm
Location: London

Postby Otto » Sat Mar 29, 2008 7:42 pm

Marco, could you post some code, please.
Thanks in advance
otto
User avatar
Otto
 
Posts: 6332
Joined: Fri Oct 07, 2005 7:07 pm

Postby Marco Turco » Sat Mar 29, 2008 9:42 pm

Sure.
In this sample the user can execute the button "Write" on the button bar with a mouse click or pressing the F2 key. I simply added a SetKey(VK_F2.. to make the same action.

Full executable available at www.softwarexp.co.uk/beta/test.zip

Obviously I would like to use a "Alt-W" key in this case but - as I know - I can't assign an Alt-<nKey> to the SetKey function so I used a function key.

*****************


#include "fivewin.ch"

function main()

local oWnd
local nClrText
local oBar2
local oFont

DEFINE FONT oFont NAME "Ms Sans Serif" SIZE 0, -10

DEFINE WINDOW oWnd TITLE "Test"


SetKey( VK_F2, { || ExecFunc(2) } )

oBar2 := TC5StBar():New( 46,10, 400, 35, oWnd, rgb(227,239,255), RGB(171,207,255), .f., oFont, nClrText )

oBar2:lRightToLeft := .f.
oWnd:oTop := oBar2
oBar2:lBorder := .t.

oBar2:AddItem( "", "bmpsmall\cambios.bmp" , {||ExecFunc(1)}, {||.t.}, .f., "accesos" )
oBar2:AddItem( "Write (F2)", "bmpsmall\capital.bmp", {||ExecFunc(2)}, {||.t.}, .f., "write" )
oBar2:AddItem( "", "bmpsmall\crossref.bmp", {||ExecFunc(3)}, {||.t.}, .f., "tareas" )
oBar2:AddItem( "", "bmpsmall\datetime.bmp", {||ExecFunc(4)}, {||.t.}, .f., "diario" )

ACTIVATE WINDOW oWnd ;
ON INIT WndCenter( oWnd:hWnd )

return nil

function ExecFunc(nMode)

if nMode=2
msginfo("Write")
endif
return nil
Best Regards,

Marco Turco
SOFTWARE XP LLP
User avatar
Marco Turco
 
Posts: 858
Joined: Fri Oct 07, 2005 12:00 pm
Location: London

Postby James Bott » Sun Mar 30, 2008 5:48 pm

Marco,

Here is an idea. Perhaps you can define a menu and then hide it (oMenu:hide()). This way you could define the hot-keys and use the Alt and Ctrl key combos. They should still work even though the menu is hidden.

James
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Postby Otto » Sun Mar 30, 2008 7:49 pm

James, I get this error:
Error description: Error BASE/1004 Message not found: TMENU:HIDE
Regards,
Otto
User avatar
Otto
 
Posts: 6332
Joined: Fri Oct 07, 2005 7:07 pm

Postby James Bott » Sun Mar 30, 2008 8:35 pm

Otto,

My mistake. It seems that TMenu does not have a hide() method.

Perhaps Antionio has an idea?

James
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Postby mmercado » Mon Mar 31, 2008 3:07 am

Hi James:
James Bott wrote:My mistake. It seems that TMenu does not have a hide() method.

Good idea, menus don't have but buttons do, you can define hidden (or placed beyond window's bounds) buttons with accelerator keys.

Regards.

Manuel Mercado
User avatar
mmercado
 
Posts: 782
Joined: Wed Dec 19, 2007 7:50 am
Location: Salamanca, Gto., México

Postby Otto » Mon Mar 31, 2008 5:52 am

Manuel,

Depending what controls in your window are active you can use
METHOD KeyDown( nKey, nFlags ).
As xBrowser usually has focus in my windows I use this method.
Maybe the METHOD KeyDown( nKey, nFlags ) from the windows class could be changed: But I don’t know if this is a good idea.

Regards,
Otto
User avatar
Otto
 
Posts: 6332
Joined: Fri Oct 07, 2005 7:07 pm

Postby James Bott » Mon Mar 31, 2008 5:58 am

Manuel,

>Good idea, menus don't have but buttons do, you can define hidden (or placed beyond window's bounds) buttons with accelerator keys.

I have used this technique before for dialogs but I never tried it with a window. Good idea.

James
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Postby Marco Turco » Mon Mar 31, 2008 3:48 pm

>Good idea, menus don't have but buttons do, you can define hidden (or placed beyond window's bounds) buttons with accelerator keys.

Yes, but the accelerator system is different beetween MENU and BUTTON.

The menu accelerator activate the ACTION method while the button accelerator only SELECT the control.
Best Regards,

Marco Turco
SOFTWARE XP LLP
User avatar
Marco Turco
 
Posts: 858
Joined: Fri Oct 07, 2005 12:00 pm
Location: London

Postby James Bott » Mon Mar 31, 2008 3:57 pm

Marco,

>The menu accelerator activate the ACTION method while the button accelerator only SELECT the control.

If I remember correctly this is not true--button hotkeys are executed just like menu hotkeys.

Have you tried it?

James
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Postby Marco Turco » Mon Mar 31, 2008 5:21 pm

I checked that in a oWnd:oWndClient context the accelerator on a button only select the control while in a dialog context the bAction method is called.

See this sample test.

#include "FiveWin.ch"

function Main()

local oWnd

DEFINE WINDOW oWnd TITLE "Test" MENU BUILDMENU() MDI

@1,1 button oBtn prompt "&Test" of oWnd:oWndClient;
ACTION MSGINFO("TEST")


ACTIVATE WINDOW oWnd

return nil


function BuildMenu()

local oMenu
local cAction

MENU oMenu
MENUITEM "Quit";
ACTION oWnd:End()
ENDMENU

RETURN(OMENU)
Best Regards,

Marco Turco
SOFTWARE XP LLP
User avatar
Marco Turco
 
Posts: 858
Joined: Fri Oct 07, 2005 12:00 pm
Location: London


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 85 guests