Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Universal Menu Concept
#1
So the older I get, the lazier I become and as such, I though... Why the hell should I waste my time making conditions f0r every menu item I include in several programs? Why not come up with a method that lets us...

1) Write the shortcut key in the data statement as it appears on our keyboard.
2) There is no friggin' step 2!

Code: (Select All)
Type MouseVar
    x As Integer
    y As Integer
    lb As Integer
    rb As Integer
    mb As Integer
    mw As Integer
    clkcnt As Integer
    caps As Integer
    shift As Integer
    ctrl As Integer
    alt As Integer
    prevx As Integer
    prevy As Integer
    drag As Integer
    sbar As Integer
    sbRow As Integer
    oldsbRow As Integer
    ThumbTop As Integer
    ThumbSize As Integer
    ThumbDrag As Integer
    autokey As String
End Type
Dim m As MouseVar

Do ' Print the menu and some info about it to the left.
    Read tmp$
    If tmp$ = "eof" Then Exit Do
    nomi = nomi + 1
    ReDim _Preserve menu$(nomi), sc$(nomi)
    menu$(nomi) = tmp$: sc$(nomi) = Chr$(3) + "0" + Chr$(4) + "0" + Chr$(5) + "0" + Space$(10)
    x$ = LCase$(Mid$(tmp$, _InStrRev(tmp$, ".") + 1))
    If InStr(x$, " ") Then
        a$ = ""
        For i = 1 To Len(x$)
            If Mid$(x$, i, 1) <> " " Then a$ = a$ + Mid$(x$, i, 1)
        Next
        x$ = a$
    End If
    If InStr(x$, "shift") Then Mid$(sc$(nomi), 2, 1) = "1"
    If InStr(x$, "ctrl") Then Mid$(sc$(nomi), 4, 1) = "1"
    If InStr(x$, "alt") Then Mid$(sc$(nomi), 6, 1) = "1"
    Mid$(sc$(nomi), 7) = Mid$(x$, _InStrRev("+" + x$, "+"))
    Print menu$(nomi), x$, sc$(nomi)
Loop
Do ' Only allow key presses in the menu. (A sound will occur if the key selection is valid).
    Mouse_Keyboard m, b$
    _Limit 30
    b$ = InKey$
    If Len(b$) Then
        e$ = LCase$(b$)
        If mshift Then
            ' Nothing needs to be added here.
        ElseIf m.ctrl Then
            Select Case e$
                Case Chr$(1): e$ = "a"
                Case Chr$(3): e$ = "x"
                Case Chr$(24): e$ = "c"
                Case Chr$(22): e$ = "v"
                Case Else ' More to be added...
            End Select
        ElseIf m.alt Then
            tmp$ = Mid$(b$, 2, 1)
            Select Case tmp$
                Case Chr$(33): e$ = "f"
                Case Else ' More to be added.
            End Select
        Else
            If Len(b$) = 1 Then
                Select Case e$
                    Case Chr$(9): e$ = "tab"
                    Case Chr$(13): e$ = "enter"
                    Case Chr$(27): e$ = "esc"
                    Case Chr$(0) + "s": e$ = "del"
                    Case Else ' More to be added.
                End Select
            Else
                tmp$ = Mid$(b$, 2, 1) ' F1-F12 Function Keys.
                If tmp$ >= Chr$(59) And tmp$ <= Chr$(68) Then e$ = "f" + LTrim$(Str$(Asc(tmp$) - 58))
                If tmp$ = Chr$(133) Then e$ = "f11" Else If tmp$ = Chr$(134) Then e$ = "f12"
            End If
        End If
        For i = 1 To nomi
            Rem Print "|"; RTrim$(Mid$(sc$(i), 7)); "|", "|"; e$; "|"; Asc(b$);: If Len(b$) = 2 Then Print Mid$(b$, 2, 1) Else Print
            If m.shift And Mid$(sc$(i), 2, 1) = "1" Or m.shift = 0 And Mid$(sc$(i), 2, 1) = "0" Then
                If m.ctrl And Mid$(sc$(i), 4, 1) = "1" Or m.ctrl = 0 And Mid$(sc$(i), 4, 1) = "0" Then
                    If m.alt And Mid$(sc$(i), 6, 1) = "1" Or m.alt = 0 And Mid$(sc$(i), 6, 1) = "0" Then
                        If RTrim$(Mid$(sc$(i), 7)) = e$ Then Sound 1000, .2: Exit For
                    End If
                End If
            End If
        Next i
    End If
Loop

MyData: ' eof must be lowercase.
Data Cut.........Ctrl+X,Copy........Ctrl+C,Paste.......Ctrl+V,Clear..........Del,Select All..Ctrl+A
Data Close..........Esc
Data Function Key....F4
Data Alt Key......Alt+F
Data Shift Key..Shift+?
Data eof

Sub Mouse_Keyboard (m As MouseVar, b$)
    Static z1
    If Len(m.autokey) Then
        b$ = Mid$(m.autokey + ",", 1, InStr(m.autokey$ + ",", ",") - 1)
        m.autokey = Mid$(m.autokey, InStr(m.autokey$ + ",", ",") + 1) ' Don't add "," tomid$() portion or the last key will always be a comma.
    Else
        b$ = InKey$
    End If
    m.prevx = m.x: m.prevy = m.y
    If m.mw Then m.mw = 0
    While _MouseInput
        m.mw = m.mw + _MouseWheel: If m.mw Then m.mw = m.mw \ Abs(m.mw) ' Limit to 1 or -1 for up or down.
    Wend
    m.x = _MouseX
    m.y = _MouseY
    If z1 Then If Abs(Timer - z1) > .25 Then z1 = 0: m.clkcnt = 0
    Select Case m.lb
        Case 2: m.lb = 0 ' Click cycle completed.
        Case 1: If _MouseButton(1) = 0 Then m.lb = 2: m.drag = 0: m.ThumbDrag = 0 ' Button released.
        Case -1: m.lb = 1 ' Button held down.
        Case 0: m.lb = _MouseButton(1)
    End Select
    Select Case m.rb
        Case 2: m.rb = 0 ' Click cycle completed.
        Case 1: If _MouseButton(2) = 0 Then m.rb = 2 ' Button released.
        Case -1: m.rb = 1 ' Button held down.
        Case 0: m.rb = _MouseButton(2)
    End Select
    Select Case m.mb
        Case 2: m.mb = 0 ' Click cycle completed.
        Case 1: If _MouseButton(3) = 0 Then m.mb = 2 ' Button released.
        Case -1: m.mb = 1 ' Button held down.
        Case 0: m.mb = _MouseButton(3)
    End Select
    If Abs(m.lb) = 1 Then
        If m.lb = -1 Then z1 = Timer: m.clkcnt = m.clkcnt + 1
        If m.prevx And m.prevx <> m.x Or m.prevy And m.prevy <> m.y Then
            If m.x <> m.prevx Then m.drag = Sgn(m.x - m.prevx) ' Prevent zero which can occur if mouse moves off row when being draged horizontally.
        End If
    End If
    If _KeyDown(100301) Then m.caps = -1 Else If m.caps Then m.caps = 0
    If _KeyDown(100303) Or _KeyDown(100304) Then m.shift = -1 Else If m.shift Then m.shift = 0
    If _KeyDown(100305) Or _KeyDown(100306) Then m.ctrl = -1 Else If m.ctrl Then m.ctrl = 0
    If _KeyDown(100307) Or _KeyDown(100308) Then m.alt = -1 Else If m.alt Then m.alt = 0
End Sub

Other methods would be like making the data in two parts...

Read name$, shortcut$
Data Activate....Ctrl+A,Chr$(1)

Where 65 is the ASCII value of A.... If Ucase$(key$) = shortcut$ Then...

It works, but it takes longer to type out the shortcut$ part then just typing: Data Activate....Ctrl+A

Anyway, I'd love to hear for anyone who has taken a similar approach, and if you found an easier way, it might make for an interesting discussion and I might even abandon this concept in favor of yours!

Pete
Reply
#2
Do you have contact for Cypherium? He made fully inclusive menu system back in like 2011 that since the original Qb64 site dropped has been lost we lost him and his code...Otherwise...NO GRAPHICS MEANS ME NO USE!!!

John
Reply
#3
(01-03-2026, 02:09 AM)Unseen Machine Wrote: Do you have contact for Cypherium? He made fully inclusive menu system back in like 2011 that since the original Qb64 site dropped has been lost we lost him and his code...Otherwise...NO GRAPHICS MEANS ME NO USE!!!

John

Hey i might have that code on my old hd.  I really liked Cypherium’s work and made a Cypherium directory on my drive to put all his code in.  I will look for it.

I remember a macos like gui you made back then.  Was pretty cool looking.  Did you develop that further?

- Dav

Find my programs here in Dav's QB64 Corner
Reply
#4
In regard to Cy... I'm a Cy-Fi fan, too... I haven't heard from him since QB64.net went offline.

In regard to addressing shortcut keys for a universal menu, this is what I came up with as a demo.

Code: (Select All)
Type MouseVar
    x As Integer
    y As Integer
    lb As Integer
    rb As Integer
    mb As Integer
    mw As Integer
    clkcnt As Integer
    caps As Integer
    shift As Integer
    ctrl As Integer
    alt As Integer
    prevx As Integer
    prevy As Integer
    drag As Integer
    sbar As Integer
    sbRow As Integer
    oldsbRow As Integer
    ThumbTop As Integer
    ThumbSize As Integer
    ThumbDrag As Integer
    autokey As String
End Type
Dim m As MouseVar

Do
    Read tmp$
    If tmp$ = "eof" Then Exit Do
    nomi = nomi + 1
    ReDim _Preserve menu$(nomi), sc$(nomi)
    menu$(nomi) = tmp$: sc$(nomi) = Chr$(3) + "0" + Chr$(4) + "0" + Chr$(5) + "0" + Space$(10)
    x$ = LCase$(Mid$(tmp$, _InStrRev(tmp$, ".") + 1))
    If InStr(x$, " ") Then
        a$ = ""
        For i = 1 To Len(x$)
            If Mid$(x$, i, 1) <> " " Then a$ = a$ + Mid$(x$, i, 1)
        Next
        x$ = a$
    End If
    If InStr(x$, "shift") Then Mid$(sc$(nomi), 2, 1) = "1"
    If InStr(x$, "ctrl") Then Mid$(sc$(nomi), 4, 1) = "1"
    If InStr(x$, "alt") Then Mid$(sc$(nomi), 6, 1) = "1"
    Mid$(sc$(nomi), 7) = Mid$(x$, _InStrRev("+" + x$, "+"))
    Print menu$(nomi), x$, sc$(nomi)
Loop
View Print CsrLin + 1 To _Height
KOnly$ = "^_`abcdefg¨©uvltjrnksp+ƒTUVWXYZ[\SP`”šˆ•—œ˜Œ’“~€„–‡‰Š‹Ž^J›†™…‘OQRC,>0" ' Space Tab Esc Enter last 4.
kOnlyName$ = "f1        f2        f3        f4        f5        f6        f7        f8        f9        f10      f11      f12      insert    delete    pgup      pgdn      home      end      arrow lt  arrow up  arrow dn  arrow rt  backspace `        1        2        3        4        5        6        7        8        9        0        -        =        q        w        e        r        t        y        u        i        o        p        [        ]        \        a        s        d        f        g        h        j        k        l        ;        '        z        x        c        v        b        n        m        ,        .        /        space    tab      esc      enter"
KShiftOnly$ = "wxyz{|}~€¨©uvltjrnksp+¡DcFGHIMKL‚Ntzhuw|xlrsž Ÿdvgijkmno]E}{fyeqp_abC2>0"
kShiftOnlyName$ = "f1        f2        f3        f4        f5        f6        f7        f8        f9        f10      f11      f12      insert    delete    pgup      pgdn      home      end      arrow lt  arrow up  arrow dn  arrow rt  backspace ~        1        2        3        4        5        6        7        8        9        0        _        +        q        w        e        r        t        y        u        i        o        p        {        }        |        a        s        d        f        g        h        j        k        l        :        " + Chr$(34) + "        z        x        c        v        b        n        m        <        >        ?        space    tab      esc      enter"
ctrlk$ = "‚ƒ„…†‡ˆ‰Š¬­µ¶§™š˜¶4Sad57<8,23>@?$6')*+-./=;&9%10–°´—C" ' Last character is Ctrl + Space.
CtrlKName$ = "f1        f2        f3        f4        f5        f6        f7        f8        f9        f10      f11      f12      insert    delete    pgup      pgdn      home      end      backspace q        w        e        r        t        y        u        i        o        p        [        ]        \        a        s        d        f        g        h        j        k        l        z        x        c        v        b        n        m        arrow lt  arrow up  arrow dn  arrow rt  space"
Altk$ = "‹Œ ‘’“”®¯ÅƼĺÂ1L›œžŸ ¡¢£¤¥¦3456789:;<=>NABCDEFGHIJKOPQRSTUVWX¾»ÃÀ" ' Alt F4 missing.
AltKName$ = "f1        f2        f3        f4        f5        f6        f7        f8        f9        f10      f11      f12      insert    delete    pgup      pgdn      home      end      backspace `        1        2        3        4        5        6        7        8        9        0        -        =        q        w        e        r        t        y        u        i        o        p        [        ]        \        a        s        d        f        g        h        j        k        l        ;        '        z        x        c        v        b        n        m        ,        .        /        arrow lt  arrow up  arrow dn  arrow rt  space"
Do
    Mouse_Keyboard m, b$
    _Limit 30
    b$ = InKey$
    If Len(b$) Then
        e$ = LCase$(b$)
        If m.ctrl Then
            If Len(b$) = 1 Then e$ = b$ Else e$ = Mid$(b$, 2, 1)
            x = InStr(ctrlk$, Chr$(Asc(e$) + 35))
            e$ = RTrim$(Mid$(CtrlKName$, x * 10 - 9, 10))
        ElseIf m.alt Then
            e$ = Mid$(b$, 2, 1)
            x = InStr(Altk$, Chr$(Asc(e$) + 35))
            e$ = RTrim$(Mid$(AltKName$, x * 10 - 9, 10))
        Else
            If Len(b$) = 1 Then e$ = b$: seed = 23 Else e$ = Mid$(b$, 2, 1): seed = 0
            If m.shift Then
                x = InStr(seed, KShiftOnly$, Chr$(Asc(e$) + 35))
                e$ = RTrim$(Mid$(kShiftOnlyName$, x * 10 - 9, 10))
            Else
                x = InStr(seed, KOnly$, Chr$(Asc(e$) + 35))
                e$ = RTrim$(Mid$(kOnlyName$, x * 10 - 9, 10))
            End If
        End If
        For i = 1 To nomi
            Rem Print "|"; RTrim$(Mid$(sc$(i), 7)); "|", "|"; e$; "|"; Asc(b$);: If Len(b$) = 2 Then Print Mid$(b$, 2, 1) Else Print
            If m.shift And Mid$(sc$(i), 2, 1) = "1" Or m.shift = 0 And Mid$(sc$(i), 2, 1) = "0" Then
                If m.ctrl And Mid$(sc$(i), 4, 1) = "1" Or m.ctrl = 0 And Mid$(sc$(i), 4, 1) = "0" Then
                    If m.alt And Mid$(sc$(i), 6, 1) = "1" Or m.alt = 0 And Mid$(sc$(i), 6, 1) = "0" Then
                        If RTrim$(Mid$(sc$(i), 7)) = e$ Then Sound 1000, .2: Exit For
                    End If
                End If
            End If
        Next i
    End If
    If Len(e$) Then
        Print "Keypress: ";
        If m.shift Then Print "Shift ";
        If m.alt Then Print "Alt ";
        If m.ctrl Then Print "Ctrl ";
        If Len(e$) > 1 Then
            Print UCase$(Left$(e$, 1)) + Mid$(e$, 2)
        Else
            If m.shift Then Print UCase$(e$) Else Print e$
        End If
        e$ = ""
    End If
Loop

' Note: eof must be lowercase.
Data Cut.........Ctrl+X,Copy........Ctrl+C,Paste.......Ctrl+V,Clear..........Del,Select All..Ctrl+A
Data Close..........Esc
Data Function Key....F4
Data Alt Key......Alt+F
Data Shift Key..Shift+?
Data eof

Sub Mouse_Keyboard (m As MouseVar, b$)
    Static z1
    If Len(m.autokey) Then
        b$ = Mid$(m.autokey + ",", 1, InStr(m.autokey$ + ",", ",") - 1)
        m.autokey = Mid$(m.autokey, InStr(m.autokey$ + ",", ",") + 1) ' Don't add "," tomid$() portion or the last key will always be a comma.
    Else
        b$ = InKey$
    End If
    m.prevx = m.x: m.prevy = m.y
    If m.mw Then m.mw = 0
    While _MouseInput
        m.mw = m.mw + _MouseWheel: If m.mw Then m.mw = m.mw \ Abs(m.mw) ' Limit to 1 or -1 for up or down.
    Wend
    m.x = _MouseX
    m.y = _MouseY
    If z1 Then If Abs(Timer - z1) > .25 Then z1 = 0: m.clkcnt = 0
    Select Case m.lb
        Case 2: m.lb = 0 ' Click cycle completed.
        Case 1: If _MouseButton(1) = 0 Then m.lb = 2: m.drag = 0: m.ThumbDrag = 0 ' Button released.
        Case -1: m.lb = 1 ' Button held down.
        Case 0: m.lb = _MouseButton(1)
    End Select
    Select Case m.rb
        Case 2: m.rb = 0 ' Click cycle completed.
        Case 1: If _MouseButton(2) = 0 Then m.rb = 2 ' Button released.
        Case -1: m.rb = 1 ' Button held down.
        Case 0: m.rb = _MouseButton(2)
    End Select
    Select Case m.mb
        Case 2: m.mb = 0 ' Click cycle completed.
        Case 1: If _MouseButton(3) = 0 Then m.mb = 2 ' Button released.
        Case -1: m.mb = 1 ' Button held down.
        Case 0: m.mb = _MouseButton(3)
    End Select
    If Abs(m.lb) = 1 Then
        If m.lb = -1 Then z1 = Timer: m.clkcnt = m.clkcnt + 1
        If m.prevx And m.prevx <> m.x Or m.prevy And m.prevy <> m.y Then
            If m.x <> m.prevx Then m.drag = Sgn(m.x - m.prevx) ' Prevent zero which can occur if mouse moves off row when being draged horizontally.
        End If
    End If
    If _KeyDown(100301) Then m.caps = -1 Else If m.caps Then m.caps = 0
    If _KeyDown(100303) Or _KeyDown(100304) Then m.shift = -1 Else If m.shift Then m.shift = 0
    If _KeyDown(100305) Or _KeyDown(100306) Then m.ctrl = -1 Else If m.ctrl Then m.ctrl = 0
    If _KeyDown(100307) Or _KeyDown(100308) Then m.alt = -1 Else If m.alt Then m.alt = 0
End Sub

So we can make whatever menu in the data section we want usng ... followed by a printed shortcut key like:

Select All .....Ctrl+A
Exit..............Esc

The system will make a sound that key or key combo is pressed, to let you know it was recognized.

Note that Alt+F4 is absent because unless I decide to trap it with _Exit, it will just end up closing the program. (Windows hot key).

Pete
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Is there a menu function? Mad Axeman 17 1,019 12-17-2025, 04:43 AM
Last Post: SMcNeill
  Trying to create a simple menu CMR 8 1,189 06-18-2025, 06:59 PM
Last Post: CookieOscar
  Enemy movement Proof Of Concept ukdave74 1 472 06-03-2025, 05:51 AM
Last Post: aadityap0901
  Another way to use Hardware Images and Transparency (alpha channel) for a PopUp Menu TempodiBasic 1 502 03-30-2025, 05:10 PM
Last Post: Pete
Question reading multiple mice from QB64PE, latest kludgey proof of concept, mostly works! madscijr 5 1,344 05-23-2024, 10:41 PM
Last Post: madscijr

Forum Jump:


Users browsing this thread: 1 Guest(s)