[solved] how to make ']' a shortcut

Just starting out? Need help? Post your questions and find answers here.
eck49
Enthusiast
Enthusiast
Posts: 153
Joined: Sat Nov 14, 2020 10:08 pm
Location: England

[solved] how to make ']' a shortcut

Post by eck49 »

Is there a way to create a shortcut to use the ']' key?

By way of illustration, take the following code - it's the PB Menu example with one line added to use F10 as a shortcut - and somehow substitute ] for F10.

Code: Select all

;
; ------------------------------------------------------------
;
;   PureBasic - Menu example file
;
;    (c) Fantaisie Software
;
; ------------------------------------------------------------
;

;
; We just have to open a window and see when an event happen on the menu
;

If OpenWindow(0, 100, 150, 195, 260, "PureBasic - Menu")

  ;
  ; Create the menu. The indent is very important here for a good lisibility
  ;
  
  AddKeyboardShortcut(0, #PB_Shortcut_F10, 11)

  If CreateMenu(0, WindowID(0))
    MenuTitle("File")
      MenuItem( 1, "&Load...")
      MenuItem( 2, "Save")
      MenuItem( 3, "Save As...")
      MenuBar()
      OpenSubMenu("Recents")
        MenuItem( 5, "Pure.png")
        MenuItem( 6, "Basic.jpg")
        OpenSubMenu("Even more !")
          MenuItem( 12, "Yeah")
        CloseSubMenu()
        MenuItem( 13, "Rocks.tga")
      CloseSubMenu()
      MenuBar()
      MenuItem( 7, "&Quit")

    MenuTitle("Edition")
      MenuItem( 8, "Cut")
      MenuItem( 9, "Copy")
      MenuItem(10, "Paste")
      
    MenuTitle("?")
      MenuItem(11, "About")

  EndIf
  
  DisableMenuItem(0, 3, 1)
  DisableMenuItem(0, 13, 1)
  
  ;
  ; This is the 'event loop'. All the user actions are processed here.
  ; It's very easy to understand: when an action occurs, the Event
  ; isn't 0 and we just have to see what have happened...
  ;
  
  Repeat

    Select WaitWindowEvent()

      Case #PB_Event_Menu

        Select EventMenu()  ; To see which menu has been selected

          Case 11 ; About
            MessageRequester("About", "Cool Menu example", 0)
            
          Default
            MessageRequester("Info", "MenuItem: "+Str(EventMenu()), 0)

        EndSelect

      Case #PB_Event_CloseWindow
        Quit = 1

    EndSelect

  Until Quit = 1

EndIf

End  
There does not appear to be an entry such as #PB_Shortcut_CloseSquareBracket, so is there a way round this? It could also apply to many other keys on the keyboard not provided for in the #PB_Shortcut list.

The setting is a standard OpenWindow program like the simple example above and it is important for consistency with other programs that the key detection can occur across the whole window and is not bound to a gadget. So solutions for a Console (etc) are ruled out.

Any solution would probably have to be vanilla PB, as this is a Linux machine.
Last edited by eck49 on Wed May 12, 2021 10:23 pm, edited 1 time in total.
Ubuntu 22.04 64-bit
Purebasic 6.00 (as of 5 Sep 2022)
(native tongue: English)
User avatar
skywalk
Addict
Addict
Posts: 3972
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: shortcut ]

Post by skywalk »

The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
BarryG
Addict
Addict
Posts: 3293
Joined: Thu Apr 18, 2019 8:17 am

Re: shortcut ]

Post by BarryG »

I don't think #VK_OEM_6 would work on Linux?
eck49
Enthusiast
Enthusiast
Posts: 153
Joined: Sat Nov 14, 2020 10:08 pm
Location: England

Re: shortcut ]

Post by eck49 »

@BarryG and skywalk - thanks for the replies.

It's true that neither #VK_OEM_6 nor what I take to be its synonym 221 work on this Linux, at least.

But 93 does.

So I have put

Code: Select all

#my_Shortcut_CloseSqBracket = 93
amongst my constants, and

Code: Select all

AddKeyboardShortcut(#WinMain, #my_Shortcut_CloseSqBracket, #shortCSB)
among list of the shortcuts.

Thanks for the pointers.

You may wonder at the long name. I just enjoy the fact that a wide IDE window means that explicitly clear names like this - where they are not used a lot in code, at least - don't have to make the code look cluttered while at the same time not needing an explanatory comment.
Ubuntu 22.04 64-bit
Purebasic 6.00 (as of 5 Sep 2022)
(native tongue: English)
User avatar
kenmo
Addict
Addict
Posts: 1967
Joined: Tue Dec 23, 2003 3:54 am

Re: [solved] how to make ']' a shortcut

Post by kenmo »

Hi, you can try my snippet here. Press any keys and it should show you the numeric shortcut value.

https://raw.githubusercontent.com/kenmo ... rtcuts.pbi

If you're running on Linux, you might have to delete a few Windows-specific constants for it to run. I'm not sure.
eck49
Enthusiast
Enthusiast
Posts: 153
Joined: Sat Nov 14, 2020 10:08 pm
Location: England

Re: [solved] how to make ']' a shortcut

Post by eck49 »

@kenmo

Thanks, that will be useful.
Ubuntu 22.04 64-bit
Purebasic 6.00 (as of 5 Sep 2022)
(native tongue: English)
BarryG
Addict
Addict
Posts: 3293
Joined: Thu Apr 18, 2019 8:17 am

Re: [solved] how to make ']' a shortcut

Post by BarryG »

Nice, kenmo. Thanks!
davido
Addict
Addict
Posts: 1890
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

Re: [solved] how to make ']' a shortcut

Post by davido »

@Kenmo,

I find this useful.
Thank you for sharing it. :D
DE AA EB
Post Reply