12-03-2022, 08:38 PM
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...
But what about x-platform methods?
Well, here is my shout out to _KEYHIT using Ctrl+ and Ctrl- to change font sizes...
Pete
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
If eggs are brain food, Biden takes his scrambled.