Jump to content

trouble creating hotkeys, porting functionalities from AHK


Recommended Posts

I need a script equivalent to the following in AHK

*r::{
    loop{
        send "e"
        sleep 2030
        if not GetKeyState("r", "P"){
            break
        }
    }
}

Basically you press "r" or "shift+r" and it sends "e", waits 2s then if you are pressing the "r" button at any point leading into the end of this 2s interval it repeats the behaviour. The 2s intervals need to be respected, so you should never be able to send "e" more than once every 2s. i.e. e...2s...e....2s....e.....5s...e....2s.....e....4s....e
I have the following:

;#RequireAdmin 
#include <MsgBoxConstants.au3>
#include <Misc.au3>

HotKeySet("{f4}", "fnTerminate")
HotKeySet("{f3}", "fnPause")
HotKeySet("r", "fnR")
HotKeySet("+r", "fnR")

func fnTerminate()
    exit
endfunc

Func fnPause()
    $g_bPaused = Not $g_bPaused
    While $g_bPaused
        Sleep(200)
        ToolTip('Script is "Paused"', 0, 0)
    WEnd
    ToolTip("")
EndFunc 

Func fnR()
    while 1
        send("e")
        Sleep(2000)
        if _IsPressed("52")=false then 
            ExitLoop
        endif
    wend
EndFunc

while 1 
    sleep(100)
wend

Your forum syntaxer didn't like the comments so I took them out. The pause function doesn't pause/suspend anything (I thought it was supposed to work by getting stuck in the loop but the other hotkeys work fine meaning the main loop never stoppped), and the loop within fnR() is just plain broken.

The behaviour in the fnR() makes no sense whatsoever to me:

Take just a simplified form of the sleep() function....why this behaviour?
How is this actually running? It seems to create infinite keypresses of "r"->"e" but only 1 instance of the code in fnR() is run.

Func fnR()
    send("e") ;works
    sleep(2000) ;DOESNT WORK

Func fnR()
    sleep(2000);works
    send("e");works


In AHK there is only 1 instance.
r::send("e") sleep(2000) 
would literally mean I can only send the letter "e" once every 2s no matter how many times I tap/hold

So I'm clearly not understanding how this process even works.  I need to be able to setup loops in my hotkey code, some kind of ifkeypressed() check function, and have duplicates of the code running for separate keys....so q->w like r->e (without any timers/loops freezing up when q and r are overlappingly active). And the ability to use ctrl/shift as hotkeys....although the doc said this isn't allowed 'because they are modifier keys!'....I find it hard to believe there is no workaround there, they work in AHK... the fact they are modifier keys doesn't exclude them from functioning as hotkeys. If the program has an outright limitation it should say so clearly.
There is no reload key like in AHK and the code for that I found online is outright broken, it'll work once initially if ur lucky. The only other thing I can think of is having a console/text-editor open(note ideal) and controlsending to it in the background, similar to how they showed u can send words offscreen to notepad. 

    If @Compiled Then
        ShellExecute(@ScriptFullPath)
    Else
        ShellExecute(@AutoItExe, @ScriptFullPath)
    EndIf

The only examples I've found for hotkeys are basic rebinds (make the "a" key work like the "b" key), and behavior related to pressing buttons on a generated GUI. The only info found on the main loop is that 'it keeps the script running' and could use a sleep of 50 to takeup less resources....that's great, but I don't understand how the runtime+sleepdelay of that mainloop interacts with the hotkeys and any loops in the hotkey etc.

Edited by kirb
Link to comment
Share on other sites

  • kirb changed the title to trouble creating hotkeys, porting functionalities from AHK
Link to comment
Share on other sites

13 minutes ago, Nine said:

You're thinking in AHK, but now you're in AutoIt.  But first of all, for what application is this aimed for ?  Looks to me for a game, right ?

Notepad

Link to comment
Share on other sites

  • Moderators

kirb,

Pull the other one! Now give us a sensible response please.

M23

P.S. And just to be absolutely clear - this is the Mod team determining the legality of the thread, so everyone else please keep out.

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

54 minutes ago, Melba23 said:

kirb,

Pull the other one! Now give us a sensible response please.

M23

P.S. And just to be absolutely clear - this is the Mod team determining the legality of the thread, so everyone else please keep out.

If the Mod team is going to support trolling then that's the Mod team's prerogative. I asked my question according to your rules, if you can't provide the answer and you are unwilling to conform to your own rules, fine, stop wasting my time. Anyone not commenting for the purposes of answering the OP's question is a troll. They are in violation of the forum rules you purport to police. Follow your own rules and police the threads properly, or end this charade. I answered the question: NOTEPAD. The script should send the keystrokes and behavior as outlined to NOTEPAD.

Link to comment
Share on other sites

  • Moderators

kirb,

If that is to be your reply then I suggest you take a short holiday from the forum and, as I suggested in your other thread, adjust your attitude when (or if) you return.

And now, begging Jos' permission...<click>

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

×
×
  • Create New...