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


Messages In This Thread
Universal Menu Concept - by Pete - 01-02-2026, 08:21 PM
RE: Universal Menu Concept - by Unseen Machine - 01-03-2026, 02:09 AM
RE: Universal Menu Concept - by Dav - 01-04-2026, 01:44 PM
RE: Universal Menu Concept - by Pete - 01-05-2026, 07:31 PM

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,196 06-18-2025, 06:59 PM
Last Post: CookieOscar
  Enemy movement Proof Of Concept ukdave74 1 474 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 504 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,345 05-23-2024, 10:41 PM
Last Post: madscijr

Forum Jump:


Users browsing this thread: 1 Guest(s)