Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Tough to ID key sequences...
#1
One ID key sequence toggle tough to identify is Ctrl + Ctrl -. It is often used in browser to enlarge or decrease text size.

I love INKEY$ but it is worthless for this one. When Ctrl is held using a PEEK routine to identify it, the + and - keys simply do not get picked up by INKEY$. Now with Windows API we can accomplish this with...

Code: (Select All)
CONST VK_CONTROL = &H11
CONST VK_OEM_PLUS = &HBB

CONST VK_OEM_MINUS = &HBD
CONST VK_ESCAPE = &H1B

DECLARE DYNAMIC LIBRARY "User32"
    FUNCTION GetAsyncKeyState% (BYVAL vkey AS LONG)
END DECLARE

DO
    _LIMIT 30
    IF GetAsyncKeyState%(VK_CONTROL) AND GetAsyncKeyState%(VK_OEM_PLUS) THEN
        PRINT "Ctrl +"
    END IF
    IF GetAsyncKeyState%(VK_CONTROL) AND GetAsyncKeyState%(VK_OEM_MINUS) THEN
        PRINT "Ctrl -"
    END IF
LOOP UNTIL GetAsyncKeyState%(VK_ESCAPE)

But what about x-platform methods?

Well, here is my shout out to _KEYHIT using Ctrl+ and Ctrl- to change font sizes...

Code: (Select All)
SCREEN 0
fontsize% = 16
style$ = "monospace"
fontpath$ = ENVIRON$("SYSTEMROOT") + "\fonts\lucon.ttf"
DIM font(8 TO 32) AS LONG
FOR i = 8 TO 32 STEP 2
    font(i) = _LOADFONT(fontpath$, i, style$)
NEXT
_FONT font(fontsize%)
ww = 600: wh = 350
WIDTH ww \ _FONTWIDTH, wh \ _FONTHEIGHT
PALETTE 7, 63: COLOR 0, 7: CLS
_FONT font(fontsize%)
_SCREENMOVE 0, 0

PRINT "Press ctrl + to increase font size or ctrl - to decrease."
DO
    _LIMIT 30
    c = _KEYHIT
    IF c THEN
        SELECT CASE c
            CASE -189
                IF fontsize% > 9 THEN fontsize% = fontsize% - 2: resizeit fontsize%, ww, wh, font()
            CASE -187
                IF fontsize% < 31 THEN fontsize% = fontsize% + 2: resizeit fontsize%, ww, wh, font()
        END SELECT
    END IF
LOOP

SUB resizeit (fontsize%, ww, wh, font() AS LONG)
    _FONT font(fontsize%)
    fw% = 0: fh% = 0
    DO
        fw% = _FONTWIDTH: fh% = _FONTHEIGHT
        IF fw% <> 0 AND fh% <> 0 THEN EXIT DO
        _DELAY .1
    LOOP
    WIDTH ww / fw%, wh / fh%
    PALETTE 7, 63: COLOR 0, 7: CLS
    _FONT font(fontsize%)
    DO: LOOP UNTIL _SCREENEXISTS: _SCREENMOVE 0, 0
    PRINT "Font size changed to:"; fontsize%: PRINT: PRINT "Window width:"; _WIDTH
    _KEYCLEAR
END SUB

Pete
Shoot first and shoot people who ask questions, later.
Reply
#2
Could use a combination of "_KEYDOWN" to check for [CTRL] hold, and "INKEY$" for minus or equals but you know that already and is less efficient. I have done something like that for a couple of programs for my own use.

First check minus or equals, don't have to check for [SHIFT] as well as [CTRL] only if that first condition is true. A music program I use irritatingly insists in my using [SHIFT] for equals key because the command is [CTRL]-plus, and otherwise it doesn't care I'm on a budget laptop which doesn't have a numeric keypad. :/
Reply
#3
Interestingly enough, INKEY won't pick up the + or minus key when ctrl is held....

Code: (Select All)
_CONTROLCHR OFF
DO
    _LIMIT 30

    DEF SEG = 0
    IF PEEK(1047) MOD 16 = 1 OR PEEK(1047) MOD 16 = 2 THEN
        KeyCombos = 1 ' Shift
    ELSEIF PEEK(1047) MOD 16 = 3 OR PEEK(1047) MOD 16 = 4 THEN
        KeyCombos = 2 ' Ctrl
    ELSEIF PEEK(1047) MOD 16 = 5 OR PEEK(1047) MOD 16 = 6 THEN
        KeyCombos = 3 ' Ctrl+Shift
    ELSEIF PEEK(1047) MOD 16 = 7 OR PEEK(1047) MOD 16 = 8 THEN
        KeyCombos = 4 ' Alt
    ELSEIF PEEK(1047) MOD 16 = 9 OR PEEK(1047) MOD 16 = 10 THEN
        KeyCombos = 5 ' Shift+Alt
    ELSEIF PEEK(1047) MOD 16 = 12 THEN
        KeyCombos = 6 ' Ctrl+Alt
    ELSEIF PEEK(1047) MOD 16 = 14 THEN
        KeyCombos = 7 ' Shift+Ctrl+Alt
    ELSE
        KeyCombos = 0
    END IF
    DEF SEG

    mykey$ = INKEY$
    IF LEN(mykey$) OR KeyCombos THEN
        SELECT CASE mykey$
            CASE CHR$(27)
                PRINT " INKEY$ CODE: CHR$(27)"
                EXIT DO ' Escape loop to end program snippet.
        END SELECT
        show_Values mykey$, KeyCombos
    END IF
LOOP

SUB show_Values (mykey$, KeyCombos)
    STATIC OldKeyCombos
    IF KeyCombos = OldKeyCombos AND LEN(mykey$) = 0 THEN EXIT SUB ' Neat trick to only print once to screen while PEEK discovered keys are held down.
    DO ' Falx loop to avoid printing INKEY printing if only a non-INKEY$ is held down.
        SELECT CASE LEN(mykey$)
            CASE 0
                EXIT DO
            CASE 1
                b = ASC(mykey$) ' ASC() converts a string character to a numeric value.
                a$ = ""
            CASE 2
                b = ASC(MID$(mykey$, 2, 1))
                a$ = "CHR$(0)" ' This is the nul character INKEY$ reports for 2 byte length key representation like the F1 - F12 keys.
        END SELECT
        b$ = LTRIM$(STR$(b)) ' This is how you convert a numeric variable to a string variable.
        PRINT " INKEY$ CODE: ";
        IF LEN(a$) THEN PRINT a$; " + ";
        PRINT "CHR$("; b$; ") "; "AKA: " + CHR$(34) + CHR$(b) + CHR$(34) + " ";
        EXIT DO
    LOOP
    IF KeyCombos THEN
        SELECT CASE KeyCombos
            CASE 1
                PRINT " Shift Down";
            CASE 2
                PRINT " Crtl Down";
            CASE 3
                PRINT " Shift + Ctrl Down";
            CASE 4
                PRINT " Alt Down";
            CASE 5
                PRINT " Shift + Alt Down";
            CASE 6
                PRINT " Ctrl + Alt Down";
            CASE 7
                PRINT " Shift + Ctrl + Alt Down";
        END SELECT
        OldKeyCombos = KeyCombos
    END IF
    PRINT
END SUB

Pete
Shoot first and shoot people who ask questions, later.
Reply
#4
FROM:

https://www.windowscentral.com/best-wind...-shortcuts
  • Ctrl + Plus (+) Zoom in.
  • Ctrl + Minus (-) Zoom out.

(Why can't this forum allow a real table displayed? I should have made sure there were tabs to separate the fields of each line.)

However I'm on Manjaro MATE and those keystroke combinations are forbidden too, even in the way I suggested to trap them. (Puts paper bag over head.)
Reply
#5
Because this forum uses cutting edge software. Any possible feature to provide us with an advantage over other board formats has been cut, cut , and cut! Big Grin

Pete
Shoot first and shoot people who ask questions, later.
Reply




Users browsing this thread: 1 Guest(s)