Jump to content

Trying to migrate a script from AHK to AutoIt


Recommended Posts

Hello everyone, i've been using AutoHotkey for a while not really by choice but because i had nothing better at hand, thing is i'm atracted by Autoit's syntax that looks more "C-ish" and i'm trying to port one of my scripts from one language to the other. Thing is it has become a huuge plate of spagetti with a lot of functions i'm not using anymore aswell as less than optimal elements.

I've hit a major roadblock so far it seems i'm unable to find a good replacement for this:

NumpadIns:: is_pressed( true )

NumpadIns up:: is_pressed( false )

Wich basically allowed me to call a function when i press a key and another when said key is released, also, it would effectively interupt the keypress from ever reaching the current aplication (it's called a system hook in c# i think)

I found the function "HotKeySet("key" [, "function"])" but it doesn't say anywhere how to get also an event triggered on key release.

So pardon me for my epic stupidity if it's actually easy to do or documented and i was too stupid to see it...

Link to comment
Share on other sites

;;*************** PRESS (END) KEY *****************


#include <Misc.au3>

$dll = DllOpen("user32.dll")

While 1
    Sleep(250)
    If _IsPressed("23", $dll) Then
        ToolTip("End Key Pressed   ", 10, 10)
        While _IsPressed("23", $dll)
            Sleep(10)
        WEnd
        ToolTip("End Key Released   ", 10, 10)
    EndIf
WEnd
DllClose($dll)

8)

NEWHeader1.png

Link to comment
Share on other sites

If you want to keep just in one loop then track the status of the key:

;;*************** PRESS (END) KEY *****************

#include <Misc.au3>

$dll = DllOpen("user32.dll")
Global $fLast = False, $fCurrent

While 1
    $fCurrent = _IsPressed("23")
    If $fCurrent <> $fLast Then
        If $fCurrent Then
            ToolTip("End Key Pressed", 10, 10)
        Else
            ToolTip("End Key Released", 10, 10)
        EndIF
        $fLast = $fCurrent
    EndIf
    Sleep(10)
WEnd

DllClose($dll)

WBD

Link to comment
Share on other sites

Thanks for your support guys ^_^

But it doesn't solve my problem, i need to be able to hook onto the keypress of some keys, so that in the event this key is pressed, i am given the choice to either silently block it or forward it to the application, also it's very time critical, so i would prefer to get some kind of "event" when said key is pressed.

pseudocode would be a bit like this:

KeypadEnter_Pressed($is_pressed)
{
    $app_is active = IsActiveWindowTheAppIMWatching();

    if($is_pressed)
    {
        if($app_is active)
            do_something()
        else
            SendKeyToApp(KeypadEnter Down)
    }
    else
    {
        if($app_is active)      
            do_something_else()
        else
            SendKeyToApp(KeypadEnter Up)
    }
}
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...