Posts: 2,910
Threads: 305
Joined: Apr 2022
Reputation:
167
So far I've managed to avoid using any Win32API calls in my current project. Ah, but now I'm adding a font increase/decrease function and I'm used to using Ctrl + and Ctrl -, in Firefox, to increase and decrease the font size. So I'd like to use the same key combos in QB64, but...
I don't believe GLUT has a way for us to map those combos, so _KeyHit, _Keydown, Inp, Inkey$, etc. don't seem to have a way to make it so. Simply put, when the control key is held down in QB64, the minus and plus keys (along with some others) are not recognized. At least that's been my experience, but maybe I'm missing something here.
Pete
Posts: 3,453
Threads: 376
Joined: Apr 2022
Reputation:
346
GLUT is brokes. It doesn't read any of the top row of keys with CTRL.
You could try ALT instead or SHIFT.
GLUT stinks!
Posts: 2,910
Threads: 305
Joined: Apr 2022
Reputation:
167
01-29-2026, 09:29 PM
(This post was last modified: 01-29-2026, 09:47 PM by Pete.)
(01-29-2026, 09:07 PM)SMcNeill Wrote: GLUT is brokes. It doesn't read any of the top row of keys with CTRL.
You could try ALT instead or SHIFT.
GLUT stinks!
For now I'll use Alt. Hey it works, but wow, I have a lot of work to do to get everything to resize properly. All the hardware images would have to be redrawn, for one.
Oh, the basic screen resize stuff...
Code: (Select All)
Dim Shared t.FSize As Integer
If t.FSize = 0 Then t.FSize = _FontHeight
Type MouseVar
x As _Byte
y As _Byte
lb As _Byte
rb As _Byte
mb As _Byte
mw As _Byte
clkcnt As _Byte
caps As _Byte
shift As _Byte
ctrl As _Byte
alt As _Byte
AltSwitch As _Byte
prevx As _Byte
prevy As _Byte
drag As _Byte
sbar As _Byte
sbRow As _Byte
oldsbRow As _Byte
ThumbTop As _Byte
ThumbSize As _Byte
ThumbDrag As _Byte
autokey As String
Pointer As _Byte
End Type
Dim m As MouseVar
Do
_Limit 30
Mouse_Keyboard m, b$
If Len(b$) Then Print b$
If m.alt Then
If b$ = Chr$(0) + "ƒ" Then t.FSize = t.FSize + 1: FontSize
If b$ = Chr$(0) + "‚" Then t.FSize = t.FSize - 1: FontSize
End If
Loop
Sub FontSize
Static CurrentFont&
rootpath$ = Environ$("SYSTEMROOT")
fontfile$ = rootpath$ + "\Fonts\lucon.ttf"
style$ = "monospace"
f& = _LoadFont(fontfile$, t.FSize, style$)
_Font f&
If CurrentFont& > 0 Then _FreeFont CurrentFont&: Sound 1000, 1
CurrentFont& = f&
Print "Hello!"
End Sub
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
If m.AltSwitch = 4 Then m.AltSwitch = 0 ' Cycle complete.
Select Case m.alt
Case _TRUE
If m.AltSwitch = 0 Then m.AltSwitch = 1 Else If m.AltSwitch = 2 Then m.AltSwitch = 3
Case Else
If m.AltSwitch = 1 Then m.AltSwitch = 2 Else If m.AltSwitch = 3 Then m.AltSwitch = 4
End Select
End Sub
Posts: 3,453
Threads: 376
Joined: Apr 2022
Reputation:
346
@Pete
Also notice that you can reduce the amount of code you're dealing with considerably by writing your types like this:
Code: (Select All)
Type GlobalVar
As _Byte anum, MyScreen
As String UcaseKeys, LcaseKeys, CtrlKeys, AltKeys
End Type
I find the above much more readable and ease to deal with than having to scroll a zillion lines with a type.
Posts: 2,910
Threads: 305
Joined: Apr 2022
Reputation:
167
01-29-2026, 09:55 PM
(This post was last modified: 01-29-2026, 10:05 PM by Pete.)
Oh I forgot we could do that with UDTs now. THANKS! +1
I edited my post above to show just the alt key increase/decrease part. That works great on simple text but with hardware images (all need resizing) and PCOPY (How to fit a screen copy in a different font size back tot the screen) it may be too much work. I mean for PCOPY The routine would have to briefly return the screen to the size of the original PCOPY screen, replace the current screen with the copy, and then bring it back to it's new size. Doable, but what a pain! Edit: Thinking... Hmm, I could just do an automatic close all open menus, which would negate the pcopy problem, followed by font size change. I would have to modify the system to redraw (rescale) the hardware images, but that shouldn't bee too much of a bother. Actually the PCOPY one might not be a big deal either, but it would probably look too strange.
Pete
Posts: 489
Threads: 17
Joined: Nov 2022
Reputation:
59
I really am bummed at how poor the keyboard handling is with GLUT.
Like we can't do a LOT of things.
@a740g let us know how we can help remove GLUT!
Posts: 520
Threads: 65
Joined: May 2022
Reputation:
86
@Pete
try this:
Code: (Select All)
Option _Explicit
Declare Dynamic Library "user32"
Function GetAsyncKeyState% (ByVal vKey As Long)
Function VkKeyScanW% (ByVal wChar As Integer)
End Declare
Const VK_SHIFT = &H10
Const VK_CONTROL = &H11
Const VK_MENU = &H12 ' Alt
Const VK_ADD = &H6B ' Numpad +
Const VK_SUBTRACT = &H6D ' Numpad -
Dim Shared vkPlus As Long, needPlus As Long
Dim Shared vkEq As Long, needEq As Long
Dim Shared vkMinus As Long, needMinus As Long
Dim Shared prevPlus%, prevMinus%
Cls
Call InitCtrlPlusMinus
Print "Press: CTRL + + / CTRL + - (can be also numpad +- or CTRL+=)"
Print "ESC = End"
Print
Do
If CtrlPlusHit% Then
Print "CTRL + PLUS (or =, or numpad +)"
End If
If CtrlMinusHit% Then
Print "CTRL + MINUS (or numpad -)"
End If
_Limit 120
Loop Until _KeyHit = 27
End
Sub InitCtrlPlusMinus
Dim r%
' '+' (ASCII 43)
r% = VkKeyScanW(43)
Call SplitVkScan(r%, vkPlus, needPlus)
' '=' (ASCII 61) -> bez Shiftu na mnoha layoutech, super jako fallback pro zoom-in
r% = VkKeyScanW(61)
Call SplitVkScan(r%, vkEq, needEq)
' '-' (ASCII 45)
r% = VkKeyScanW(45)
Call SplitVkScan(r%, vkMinus, needMinus)
prevPlus% = 0
prevMinus% = 0
End Sub
Sub SplitVkScan (r%, vkOut As Long, needOut As Long)
Dim rr&
' VkKeyScanW vraci -1 kdyz znak nejde namapovat 'return -1 if chcaracter can not be mapped
If r% = -1 Then
vkOut = 0
needOut = 0
Exit Sub
End If
rr& = r%
vkOut = (rr& And &HFF&)
needOut = ((rr& And &HFF00&) \ &H100&) ' 1=Shift, 2=Ctrl, 4=Alt
End Sub
Function KeyDown% (vk As Long)
Dim st%
st% = GetAsyncKeyState(vk)
If st% < 0 Then
KeyDown% = -1
Else
KeyDown% = 0
End If
End Function
Function ModifiersOk% (need As Long)
Dim ok%
ok% = -1
If (need And 1) <> 0 Then
If KeyDown%(VK_SHIFT) = 0 Then ok% = 0
End If
If (need And 2) <> 0 Then
If KeyDown%(VK_CONTROL) = 0 Then ok% = 0
End If
If (need And 4) <> 0 Then
If KeyDown%(VK_MENU) = 0 Then ok% = 0
End If
ModifiersOk% = ok%
End Function
Function CtrlPlusHit%
Dim down%
down% = 0
If KeyDown%(VK_CONTROL) Then
' Numpad +
If KeyDown%(VK_ADD) Then down% = -1
' Layout-aware '+' a '='
If vkPlus <> 0 Then
If KeyDown%(vkPlus) Then
If ModifiersOk%(needPlus) Then down% = -1
End If
End If
If vkEq <> 0 Then
If KeyDown%(vkEq) Then
If ModifiersOk%(needEq) Then down% = -1
End If
End If
End If
If down% Then
If prevPlus% = 0 Then CtrlPlusHit% = -1
prevPlus% = -1
Else
prevPlus% = 0
CtrlPlusHit% = 0
End If
End Function
Function CtrlMinusHit%
Dim down%
down% = 0
If KeyDown%(VK_CONTROL) Then
' Numpad -
If KeyDown%(VK_SUBTRACT) Then down% = -1
' Layout-aware '-'
If vkMinus <> 0 Then
If KeyDown%(vkMinus) Then
If ModifiersOk%(needMinus) Then down% = -1
End If
End If
End If
If down% Then
If prevMinus% = 0 Then CtrlMinusHit% = -1
prevMinus% = -1
Else
prevMinus% = 0
CtrlMinusHit% = 0
End If
End Function
Posts: 957
Threads: 52
Joined: May 2022
Reputation:
38
@Pete - have you ever tried FreeGlut? I don't know anything about it myself, I've just been researching it. FreeGlut
Posts: 2,910
Threads: 305
Joined: Apr 2022
Reputation:
167
In a word, no.
Pete
|