Different output depends on how long to hold a key Topic is solved

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

Different output depends on how long to hold a key

Post by akirofe » 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: 230
Joined: 21 Mar 2023, 06:52

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

Post by WarlordAkamu67 » 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: 161
Joined: 05 Apr 2021, 21:54

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

Post by akirofe » 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! ***

akirofe
Posts: 161
Joined: 05 Apr 2021, 21:54

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

Post by akirofe » 22 May 2024, 21:47

IT WORKS B.E.A.U.T.I.F.U.L.L.Y dear WarlordAkamu67 !!! I am sooooo happy and grateful!!! How can I buy you beers please PM me :bravo: :bravo: :bravo: :bravo: :bravo: :bravo:
*** 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: 230
Joined: 21 Mar 2023, 06:52

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

Post by WarlordAkamu67 » 23 May 2024, 05:42

@akirofe
Thank you for the offer, cheers. :beer:

I am glad to hear it worked out ^.^ ... It is most helpful for topics with solutions to be marked as solved/resolved.

teadrinker
Posts: 4389
Joined: 29 Mar 2015, 09:41
Contact:

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

Post by teadrinker » 23 May 2024, 21:10

You can make it a little easier:

Code: Select all

F3:: {
    BlockInput('MouseMove'),
    KeyWait('F3', 'T.3') && Send('{Enter}')
    KeyWait 'F3'
    BlockInput 'MouseMoveOff'
}
:)

Post Reply

Return to “Ask for Help (v2)”