Window menu Alt+hotkey

Just starting out? Need help? Post your questions and find answers here.
debashisde
User
User
Posts: 11
Joined: Wed Oct 27, 2010 5:33 am

Re: Window menu Alt+hotkey

Post by debashisde »

skywalk wrote:I have never gotten a button(command button in VB6) to fire with the "&" something keystroke in any Windows version.
Only [Enter] or [Spacebar] when it has the focus.
In VB6, if you specify caption of a button with "&" like here I did as "&Add".
VB6 will show it as "Add" and will activate the button on pressing Alt-A.
You do not have to do anything special for that (like AddKeyBoardShortCut etc).
It will be done automatically. Ask any VB programmer and he will tell you.
User avatar
Shardik
Addict
Addict
Posts: 2058
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: Window menu Alt+hotkey

Post by Shardik »

debashisde wrote:In Windows, when I run the program using "F5" it shows "Add", but when I start it by clicking the "Compile/Run" tool button the underline character is not shown, the label becomes plain "Add".
Testing with PB 4.51 in Windows XP SP3 the underline character is always displayed
(independently how I start debashisde's last example code), if hiding the alt key is
disabled and never displayed if hiding the alt key is enabled like I described in my
previous posting:
Shardik wrote:If somebody wants the underlined character in Windows to be displayed permanantly
(if XP Skins is enabled) he has to uncheck the option
Hide underlined letters for keyboard navigation until I press the Alt key
in Display Properties --> Appearance --> Effects.
Testing with PB 4.51 in Windows 7 x86 I obtained the same results. In Windows 7
you have to enable the option in "Control Panel"/"Ease of Access Center"/"Make the
Keyboard easier to use" in order to see the underlined character A.
Last edited by Shardik on Thu Nov 11, 2010 4:47 pm, edited 1 time in total.
User avatar
Shardik
Addict
Addict
Posts: 2058
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: Window menu Alt+hotkey

Post by Shardik »

I have expanded debashisde's last code example to correctly display the
underlined character A on a button in Windows and Linux (in Linux I had
to use two API calls):

Code: Select all

#window_0 = 0
#button_0 = 1
#app_name = "Test"

OpenWindow(#window_0, #PB_Ignore, #PB_Ignore, 300, 200, #app_name, #PB_Window_SystemMenu | #PB_Window_ScreenCentered)

CompilerSelect #PB_Compiler_OS
  CompilerCase #PB_OS_Linux
    ButtonGadget(#button_0, 100, 100, 100, 30, "")
    gtk_button_set_label_(GadgetID(#button_0), "_Add")
    gtk_button_set_use_underline_(GadgetID(#button_0), #True)
  CompilerCase #PB_OS_Windows
    ButtonGadget(#button_0, 100, 100, 100, 30, "&Add")
CompilerEndSelect

AddKeyboardShortcut(#window_0, #PB_Shortcut_Alt | #PB_Shortcut_A, #button_0)

Repeat
  event = WaitWindowEvent()
 
  Select event
    Case #PB_Event_Gadget, #PB_Event_Menu
      Select (EventGadget())
        Case #button_0
          MessageRequester(#app_name, "button clicked")
      EndSelect
  EndSelect
Until event = #PB_Event_CloseWindow
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4946
Joined: Sun Apr 12, 2009 6:27 am

Re: Window menu Alt+hotkey

Post by RASHAD »

For Windows

Code: Select all

#window_0 = 0
#button_0 = 1
#app_name = "Test"
;#SPI_SETKEYBOARDCUES = $100B

Global Pv.l

SystemParametersInfo_(#SPI_GETKEYBOARDCUES, 0, @Pv, 0)
SystemParametersInfo_(#SPI_SETKEYBOARDCUES, 0, 1, 0)  

OpenWindow(#window_0, #PB_Ignore, #PB_Ignore, 300, 200, #app_name, #PB_Window_SystemMenu | #PB_Window_ScreenCentered)

ButtonGadget(#button_0, 100, 100, 100, 30, "&Add")

AddKeyboardShortcut(#window_0, #PB_Shortcut_Alt | #PB_Shortcut_A, #button_0)

Repeat
  event = WaitWindowEvent()
 
  Select event
    Case #PB_Event_Gadget, #PB_Event_Menu
      Select (EventGadget())
        Case #button_0
          MessageRequester(#app_name, "button clicked")
      EndSelect
  
      Case #PB_Event_CloseWindow      
        If Pv = 0
            SystemParametersInfo_(#SPI_SETKEYBOARDCUES, 0, 0, 0)
        EndIf
        Quit = 1
  EndSelect
        
Until Quit = 1

Egypt my love
User avatar
skywalk
Addict
Addict
Posts: 4211
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: Window menu Alt+hotkey

Post by skywalk »

debashisde wrote: In VB6, if you specify caption of a button with "&" like here I did as "&Add".
VB6 will show it as "Add" and will activate the button on pressing Alt-A.
You do not have to do anything special for that (like AddKeyBoardShortCut etc).
It will be done automatically. Ask any VB programmer and he will tell you.
Whoa! You are correct.
I don't know when that was implemented, but thanks.
I've been using VB since 1.0. :oops:
What forum am I on now? :lol:
debashisde
User
User
Posts: 11
Joined: Wed Oct 27, 2010 5:33 am

Re: Window menu Alt+hotkey

Post by debashisde »

Shardik wrote:Testing with PB 4.51 in Windows 7 x86 I obtained the same results. In Windows 7
you have to enable the option in "Control Panel"/"Ease of Access Center"/"Make the
Keyboard easier to use" in order to see the underlined character A.
Ok, thanks for the info. I am sorry, probably I overlooked this one.
The machine on which I tested was a Windows 7 system.
I will try it again by changing the setting as you said when I get to the machine.
Thanks again.
debashisde
User
User
Posts: 11
Joined: Wed Oct 27, 2010 5:33 am

Re: Window menu Alt+hotkey

Post by debashisde »

Shardik wrote:I have expanded debashisde's last code example to correctly display the
underlined character A on a button in Windows and Linux (in Linux I had
to use two API calls):

Code: Select all

#window_0 = 0
#button_0 = 1
#app_name = "Test"

OpenWindow(#window_0, #PB_Ignore, #PB_Ignore, 300, 200, #app_name, #PB_Window_SystemMenu | #PB_Window_ScreenCentered)

CompilerSelect #PB_Compiler_OS
  CompilerCase #PB_OS_Linux
    ButtonGadget(#button_0, 100, 100, 100, 30, "")
    gtk_button_set_label_(GadgetID(#button_0), "_Add")
    gtk_button_set_use_underline_(GadgetID(#button_0), #True)
  CompilerCase #PB_OS_Windows
    ButtonGadget(#button_0, 100, 100, 100, 30, "&Add")
CompilerEndSelect

AddKeyboardShortcut(#window_0, #PB_Shortcut_Alt | #PB_Shortcut_A, #button_0)

Repeat
  event = WaitWindowEvent()
 
  Select event
    Case #PB_Event_Gadget, #PB_Event_Menu
      Select (EventGadget())
        Case #button_0
          MessageRequester(#app_name, "button clicked")
      EndSelect
  EndSelect
Until event = #PB_Event_CloseWindow
Thanks for the code, but I can not check it as I am using a demo version and it says:
******************************************
PureBasic 4.51 (Linux - x86) Demo
******************************************

Loading external modules...
Starting compilation...
Error: Line 10 - gtk_button_set_label_() is not a function (or not available in demo version), macro, array or linked list.
Anyway, now, I know that there is a way to achieve it. Thanks.
debashisde
User
User
Posts: 11
Joined: Wed Oct 27, 2010 5:33 am

Re: Window menu Alt+hotkey

Post by debashisde »

debashisde wrote:
Shardik wrote:Testing with PB 4.51 in Windows 7 x86 I obtained the same results. In Windows 7
you have to enable the option in "Control Panel"/"Ease of Access Center"/"Make the
Keyboard easier to use" in order to see the underlined character A.
Ok, thanks for the info. I am sorry, probably I overlooked this one.
The machine on which I tested was a Windows 7 system.
I will try it again by changing the setting as you said when I get to the machine.
Thanks again.
I confirm that changing the settings as said by Shardik works perfectly.
Thanks everyone for your help.
Post Reply