' menu_shortcut.pb — Keyboard shortcut system simulation
#COMPILE EXE
#DIM ALL

FUNCTION PBMAIN() AS LONG
    LOCAL keyCodes(30) AS LONG
    LOCAL handlerIDs(30) AS LONG
    LOCAL count AS LONG
    LOCAL i AS LONG
    LOCAL j AS LONG
    LOCAL code AS LONG
    LOCAL handler_id AS LONG
    LOCAL found AS LONG
    LOCAL total AS LONG
    LOCAL steps AS LONG
    LOCAL key AS LONG
    LOCAL temp AS LONG
    LOCAL result AS LONG
    LOCAL searchKey AS LONG
    LOCAL maxShortcuts AS LONG
    LOCAL modCount AS LONG

    maxShortcuts = 15

    keyCodes(0) = 78
    handlerIDs(0) = 100
    keyCodes(1) = 79
    handlerIDs(1) = 101
    keyCodes(2) = 83
    handlerIDs(2) = 102
    keyCodes(3) = 80
    handlerIDs(3) = 103
    keyCodes(4) = 70
    handlerIDs(4) = 104
    keyCodes(5) = 90
    handlerIDs(5) = 105
    keyCodes(6) = 89
    handlerIDs(6) = 106
    keyCodes(7) = 67
    handlerIDs(7) = 107
    keyCodes(8) = 86
    handlerIDs(8) = 108
    keyCodes(9) = 88
    handlerIDs(9) = 109
    keyCodes(10) = 65
    handlerIDs(10) = 110
    keyCodes(11) = 68
    handlerIDs(11) = 111
    keyCodes(12) = 82
    handlerIDs(12) = 112
    keyCodes(13) = 84
    handlerIDs(13) = 113
    keyCodes(14) = 73
    handlerIDs(14) = 114
    count = 15

    PRINT "=== Shortcut Key Manager ==="
    PRINT "Registered shortcuts: " + STR$(count)

    FOR i = 0 TO count - 1
        code = keyCodes(i)
        handler_id = handlerIDs(i)
        result = code + handler_id
        total = total + result
        IF code = 78 THEN
            PRINT "  N (" + STR$(code) + ") -> handler " + STR$(handler_id)
        END IF
        IF code = 79 THEN
            PRINT "  O (" + STR$(code) + ") -> handler " + STR$(handler_id)
        END IF
        IF code = 83 THEN
            PRINT "  S (" + STR$(code) + ") -> handler " + STR$(handler_id)
        END IF
        IF code = 80 THEN
            PRINT "  P (" + STR$(code) + ") -> handler " + STR$(handler_id)
        END IF
        IF code = 70 THEN
            PRINT "  F (" + STR$(code) + ") -> handler " + STR$(handler_id)
        END IF
        IF code = 90 THEN
            PRINT "  Z (" + STR$(code) + ") -> handler " + STR$(handler_id)
        END IF
        IF code = 89 THEN
            PRINT "  Y (" + STR$(code) + ") -> handler " + STR$(handler_id)
        END IF
        IF code = 67 THEN
            PRINT "  C (" + STR$(code) + ") -> handler " + STR$(handler_id)
        END IF
        IF code = 86 THEN
            PRINT "  V (" + STR$(code) + ") -> handler " + STR$(handler_id)
        END IF
        IF code = 88 THEN
            PRINT "  X (" + STR$(code) + ") -> handler " + STR$(handler_id)
        END IF
        IF code = 65 THEN
            PRINT "  A (" + STR$(code) + ") -> handler " + STR$(handler_id)
        END IF
        IF code = 68 THEN
            PRINT "  D (" + STR$(code) + ") -> handler " + STR$(handler_id)
        END IF
        IF code = 82 THEN
            PRINT "  R (" + STR$(code) + ") -> handler " + STR$(handler_id)
        END IF
        IF code = 84 THEN
            PRINT "  T (" + STR$(code) + ") -> handler " + STR$(handler_id)
        END IF
        IF code = 73 THEN
            PRINT "  I (" + STR$(code) + ") -> handler " + STR$(handler_id)
        END IF
    NEXT i
    PRINT "Checksum total: " + STR$(total)

    FOR steps = 1 TO count
        key = keyCodes(steps - 1)
        found = -1
        FOR j = 0 TO count - 1
            IF keyCodes(j) = key THEN
                found = j
            END IF
        NEXT j
        IF found >= 0 THEN
            temp = handlerIDs(found)
            PRINT "Pressed code " + STR$(key) + ": execute handler " + STR$(temp)
        END IF
    NEXT steps

    PRINT "Searching for code 99..."
    searchKey = 99
    found = -1
    FOR j = 0 TO count - 1
        IF keyCodes(j) = searchKey THEN
            found = j
        END IF
    NEXT j
    IF found >= 0 THEN
        PRINT "Found at index " + STR$(found)
    ELSE
        PRINT "Not found"
    END IF

    PRINT "Total shortcuts: " + STR$(count)
    PRINT "=== End Shortcut Manager ==="
    FUNCTION = 0
END FUNCTION
