Different output depends on how long to hold a key

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
akirofe
Posts: 150
Joined: 05 Apr 2021, 21:54

Different output depends on how long to hold a key

14 Mar 2024, 21:43

Hi awesome people :) ,

Could you please kindly help me?

Could you please help me with a codes (or if you don't have time, a link for what to read specifically to do this:) so that:

For a key (say, F3):

1. While being pressed, it will stop mouse movement (so I can re-position my mouse without have to lift it up the mouse mat). And If I press another key while being pressed, it will do something else, say writing my email address automatically.
2. If I release quickly like a normal keypress action (without pressing any other key), it will send "Enter".
(3. And when I release, it will of course resume normal mouse movement.)

Thank you very much! <3
*** Thank you for reading. I am not in coding and know almost nothing about professional coding, hope for your patience and deeply appreciate any of your kind helps. My current interest in this awesome AHK is due to that my work is graphical ((architect/CAD) and, to reduce strains, my right hand is better off not leaving the mouse (an MMO mouse that has 12 side keys which I maps a lot of F keys and other keys in) as much as possible. All the best you lovely coders! ***
User avatar
WarlordAkamu67
Posts: 220
Joined: 21 Mar 2023, 06:52

Re: Different output depends on how long to hold a key

20 Mar 2024, 06:38

@akirofe This will make F3 send Enter on a press, and block mouse movement on a hold. While holding F3, the keys "a", "b", and "c" can be used to display a MsgBox- alter to your liking.

Code: Select all

#Requires AutoHotkey v2.0

key_is_Held := 0

; ------------------------- ; ------------------------- ; ------------------------- ; ------------------------- ; ------------------------- ; ------------------------- ; ------------------------- ; ------------------------- ; ------------------------- ; ------------------------- ;
; ------------------------- ; ------------------------- ; ------------------------- ; ------------------------- ; ------------------------- ; ------------------------- ; ------------------------- ; ------------------------- ; ------------------------- ; ------------------------- ;
; ------------------------- ; ------------------------- ; ------------------------- ; ------------------------- ; ------------------------- ; ------------------------- ; ------------------------- ; ------------------------- ; ------------------------- ; ------------------------- ;

multiKey() {
  if (GetKeyState("F3", "P")) {
    BlockInput("MouseMove")
    global key_is_Held := 1
    while (GetKeyState("F3", "P")) {
      Sleep(100)
}
    global key_is_Held := 0
    BlockInput("MouseMoveOff")
} else {
    Send("{Enter}")
}
  return
}

; ------------------------- ; ------------------------- ; ------------------------- ; ------------------------- ; ------------------------- ; ------------------------- ; ------------------------- ; ------------------------- ; ------------------------- ; ------------------------- ;
; ------------------------- ; ------------------------- ; ------------------------- ; ------------------------- ; ------------------------- ; ------------------------- ; ------------------------- ; ------------------------- ; ------------------------- ; ------------------------- ;
; ------------------------- ; ------------------------- ; ------------------------- ; ------------------------- ; ------------------------- ; ------------------------- ; ------------------------- ; ------------------------- ; ------------------------- ; ------------------------- ;

F3:: {
  SetTimer(multiKey, -200)
  KeyWait("F3")
  return
}

; ------------------------- ; ------------------------- ; ------------------------- ; ------------------------- ; ------------------------- ; ------------------------- ; ------------------------- ; ------------------------- ; ------------------------- ; ------------------------- ;

#HotIf (key_is_Held)
a:: {
  MsgBox("Extra Function on F3 + a")
  return
}

b:: {
  MsgBox("Extra Function on F3 + b")
  return
}

c:: {
  MsgBox("Extra Function on F3 + c")
  return
}
akirofe
Posts: 150
Joined: 05 Apr 2021, 21:54

Re: Different output depends on how long to hold a key

27 Mar 2024, 02:29

Wow... Thank you very much WarlordAkamu67 !!! I'll apply and will report back!!! Have a wonderful day WarlordAkamu67 !!
*** Thank you for reading. I am not in coding and know almost nothing about professional coding, hope for your patience and deeply appreciate any of your kind helps. My current interest in this awesome AHK is due to that my work is graphical ((architect/CAD) and, to reduce strains, my right hand is better off not leaving the mouse (an MMO mouse that has 12 side keys which I maps a lot of F keys and other keys in) as much as possible. All the best you lovely coders! ***

Return to “Ask for Help (v2)”

Who is online

Users browsing this forum: Felix Siano, Google [Bot] and 59 guests