Skip to content

Commit

Permalink
Fix hotkeys to support press+and+hold behavior
Browse files Browse the repository at this point in the history
Relates to #425.  Thank you to @mythter for catching and reporting!
  • Loading branch information
tannerhelland committed Aug 22, 2024
1 parent 5a6204a commit a1e4603
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 24 deletions.
45 changes: 22 additions & 23 deletions Controls/pdAccelerator.ctl
Original file line number Diff line number Diff line change
Expand Up @@ -516,32 +516,31 @@ Friend Function KeyboardHookProcAccelerator(ByVal nCode As Long, ByVal wParam As
' that are full transitions from "Unpressed" to "Pressed" or vice-versa. (The byte masks here
' all come from MSDN - check the link above for details!)
'
'TODO: some hotkeys (like brush size up/down) would actually benefit from key repeat behavior.
' This line needs to be revisited accordingly!
If ((lParam >= 0) And ((lParam And &H40000000) = 0)) Or ((lParam < 0) And ((lParam And &H40000000) <> 0)) Then

'We now want to check two things simultaneously. First, we want to update Ctrl/Alt/Shift
' key state tracking. (This is handled by a separate function.) If something other than
' Ctrl/Alt/Shift was pressed, *and* this is a keydown event, let's look for hotkey matches.
'
'(How do we detect keydown vs keyup events? The first bit (e.g. "bit 31" per MSDN) of lParam
' defines key state: 0 means the key is being pressed, 1 means the key is being released.
' Note the similarity to the transition check, above.)
If (lParam >= 0) And (Not UpdateCtrlAltShiftState(wParam, lParam)) Then

'Before proceeding with further checks, see if PD is even allowed to process accelerators
' in its current state (e.g. if a modal dialog is active, we don't want to raise events)
If CanIAccumulateAnAccelerator Then
'(Update 2024: some hotkeys (like brush size up/down) actually benefit from key repeat behavior.
' To enable this, I removed the old transition state check. If for some reason we need to enable
' it in the future, use the boolean calculation below.)
'Dim keyTransitionState As Boolean
'keyTransitionState = ((lParam >= 0) And ((lParam And &H40000000) = 0)) Or ((lParam < 0) And ((lParam And &H40000000) <> 0))

'We now want to check two things simultaneously. First, we want to update Ctrl/Alt/Shift
' key state tracking. (This is handled by a separate function.) If something other than
' Ctrl/Alt/Shift was pressed, *and* this is a keydown event, let's look for hotkey matches.
'
'(How do we detect keydown vs keyup events? The first bit (e.g. "bit 31" per MSDN) of lParam
' defines key state: 0 means the key is being pressed, 1 means the key is being released.
' Note the similarity to the transition check, above.)
If (lParam >= 0) And (Not UpdateCtrlAltShiftState(wParam, lParam)) Then

'Before proceeding with further checks, see if PD is even allowed to process accelerators
' in its current state (e.g. if a modal dialog is active, we don't want to raise events)
If CanIAccumulateAnAccelerator Then

'All checks have passed. We'll handle the actual keycode evaluation matching in another function.
msgEaten = HandleActualKeypress(nCode, wParam, lParam)

'All checks have passed. We'll handle the actual keycode evaluation matching in another function.
msgEaten = HandleActualKeypress(nCode, wParam, lParam)

End If

'/Ctrl/Alt/Shift was pressed
End If

'/Key is not in a transitionary state
'/Ctrl/Alt/Shift was pressed
End If

'/nCode negative
Expand Down
2 changes: 1 addition & 1 deletion PhotoDemon.vbp
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ Description="PhotoDemon Photo Editor"
CompatibleMode="0"
MajorVer=2024
MinorVer=8
RevisionVer=24
RevisionVer=25
AutoIncrementVer=1
ServerSupportFiles=0
VersionComments="Copyright 2000-2024 Tanner Helland - photodemon.org"
Expand Down

0 comments on commit a1e4603

Please sign in to comment.