Strange behavior for Hotkeys that are implemented with Wildcard

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Roland

Strange behavior for Hotkeys that are implemented with Wildcard

15 Mar 2018, 07:12

Hi, in the following simple script i implement hotkeys for most keys on the keyboard.

They are created all in the same way with WIldcard(*) so that they also trigger while other keys are pressed.
The script shows a tooltip with the registered keys as soon as all keys are released.

My Problem is that if i press
a
s
d
d up
s up
a up

it shows this order correctly in the tooltip.

But if i do,
d
f
g
g up
f up
d up

then i get in the tooltip:
d
f
f up
d up

So the g key isnt registered anymore which is surprising because the code treats all these keys equally.

If i only press g then it is registered so "g" was definitly not forgotten in the Hotkey implementation

Am i missing something here?
Can you confirm that you get the same Output as i do? It might be my computer that is doing something odd.
(Otherwise i would suspect that the reason lies in the intrinsic code for hotkeys)

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
#Persistent
global hkHistory
global pressedAKey

hkHistory:=""
pressedAKey:=0
hotkeys()

SetTimer , checkForFullKeyRelease, 150

return

;#########################Hotkeys#####################################


hotkeys(on = true) {		;sets hotkeys for most keys on the keyboard, except Page Up and so on...
   ;#MaxThreadsPerHotkey 1
   ;#UseHook
   nums=0123456789ABCDEF
   StringSplit numarray, nums

   Loop %numarray0%
   {
      n1 := numarray%A_Index%
      Loop %numarray0%
      {
         n2 := numarray%A_Index%
         n := n1 . n2
         
         
         if n=00		;no Mouse buttons
            continue
         if n=01
            continue
         if n=02
            continue
         if n=04
            continue

			 k := "*VK" . n				; 	*: also fire if there are already other keys pressed
    
		if (n="1B")		;This is ESC, dont set for it since it is used to exit the script
		   continue
            Hotkey, %k%, LogKey, % "B" . (on ? "On" : "Off") ;%
            Hotkey, %k% up, LogKeyUp, % "B" . (on ? "On" : "Off") ;%
      }
   }
   
}

ESC::
ExitApp
return

;#########################Labels#####################################

LogKey:
pressedAKey:=1			;this variable is needed so that the Timer keeps showing the last key combination that was fully released
v:=A_ThisHotkey
StringTrimLeft, v, v, 1 ; -1 to remove "*"
hkHistory := hkHistory .  GetKeyName(v) . "`n"
return

LogKeyUp:
pressedAKey:=1
v:=A_ThisHotkey
StringTrimLeft, v, v, 1 ; -1 to remove "*"
hkHistory := hkHistory . GetKeyName(v) . " up`n"
return



checkForFullKeyRelease:				;Timer to show keys in a tooltip
if(allKeysUp()&&pressedAKey)
{
	TTatRandLoc(hkHistory)		;create Tooltip with String hkHistory
	
	hkHistory:=""				; all keys are up, begina new string.
	pressedAKey:=0				;set to 0 so that the Tooltip is not updated the next time the Timer is called, only if keys were pressed in the meantime and all Keys are released now
}
return



allKeysUp(){					;goes thorugh all keys and returns 1 if none is physically pressed

   
   nums=0123456789ABCDEF
   StringSplit numarray, nums

   Loop %numarray0%
   {
      n1 := numarray%A_Index%
      Loop %numarray0%
      {
         n2 := numarray%A_Index%
         n := n1 . n2
         
         
         if n=00		;no Mouse buttons
            continue
         if n=01
            continue
         if n=02
            continue
         if n=04
            continue

         k := "VK" . n
		 GetKeyState, state, %k%,P
         if  (state=="D")
		{
            return 0
		}
      }
   }
   return 1
}



TTatRandLoc(stringToShow)
{
			Random, rand1, 0.4, 0.6
			detX:=rand1*A_ScreenWidth
			Random, rand2, 0.4, 0.6
			detY:=rand2*A_ScreenHeight
			tooltip, %stringToShow%,detX,detY,9
}

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: joefiesta and 289 guests