"media_prev" key misbehaves when I include "enter" key. Topic is solved

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
alawsareps
Posts: 38
Joined: 20 Jul 2016, 09:28

"media_prev" key misbehaves when I include "enter" key.

03 May 2024, 01:52

When I long press "media_prev" without the "enter", it works fine. it sends "__LONG.press.prev" after 300ms.

however, when I include "enter", "media_prev" misbehaves. it repetitively send "__short.press.prev" while the key is pressed.

how can I solve this ?

Code: Select all

#Requires AutoHotkey v2.0

media_prev:: {

    startTime := A_TickCount
    While GetKeyState("media_prev", "P") {  
        if ((A_TickCount - startTime) > 300) {   
            send("__LONG.press.prev")
            KeyWait("media_prev")
            return
        }
    }
    ;------------ SHORT PRESS
    send ("__short.press.prev")
    
return
}

enter:: {
     send("enter key")
}
niCode
Posts: 335
Joined: 17 Oct 2022, 22:09

Re: "media_prev" key misbehaves when I include "enter" key.

03 May 2024, 02:46

I'm quite curious to see what others have to say about this because I'm experiencing the same thing in a new script and all other scripts closed.

Including Enter:: seems to cause KeyWait to not recognize Media_Prev or something.

It also fails If the hotkey uses the keyboard hook $Media_Prev:: *Media_Prev:: InstallKeybdHook #UseHook etc.

It doesn't fail if I have, say, x::ToolTip('hey')

But if x uses the keyboard hook, then Media_Prev fails again.

This feels like a bug to me.


By the way, you can use KeyWait to check if a key was released within a certain amount of time:

Code: Select all

Media_Prev:: {
    if KeyWait('Media_Prev', 'T0.3') {
        Send("__short.press.prev")
    } else {
        Send("__LONG.press.prev")
        KeyWait('Media_Prev')
    }
}
User avatar
Noitalommi_2
Posts: 393
Joined: 16 Aug 2023, 10:58

Re: "media_prev" key misbehaves when I include "enter" key.  Topic is solved

03 May 2024, 09:37

Hi.

This works on my end, I have added the logical state (L) of KeyWait.

Code: Select all

#Requires AutoHotkey v2.0

Media_Prev:: {
    if KeyWait('Media_Prev', 'LT0.3') {
        Send("__short.press.prev")
    } else {
        Send("__LONG.press.prev")
        KeyWait('Media_Prev', "L")
    }
}

enter::send("enter key")
Last edited by Noitalommi_2 on 03 May 2024, 10:11, edited 1 time in total.
alawsareps
Posts: 38
Joined: 20 Jul 2016, 09:28

Re: "media_prev" key misbehaves when I include "enter" key.

03 May 2024, 09:50

@Noitalommi_2

Hi, I tried you're code.

However, it still behaves differently than it's supposed to.

Long pressing "Media_Prev" will send "__LONG.press.prev" repetitively, instead of just once.
User avatar
Noitalommi_2
Posts: 393
Joined: 16 Aug 2023, 10:58

Re: "media_prev" key misbehaves when I include "enter" key.

03 May 2024, 10:13

@alawsareps

I also added “L” to the second KeyWait, it should work now.

Return to “Ask for Help (v2)”

Who is online

Users browsing this forum: DavidP, prius1234, vanove and 90 guests