Sign in to follow this  
Followers 0
Newtoai

How to do a global HotKeySet ?

8 posts in this topic

#1 ·  Posted (edited)

Hello, I've started with AI today, after comparing to AHK, and I tried for several hours to get some info to the most basic of questions, in vain.

I know the command HotKeySet, but I do not understand it.

I'm coming from a traditional macro program but which is not strong enough, has not enough functionality in order for me to do what I want. Then I evaluated a lot of other traditional / commercial macro programs, and they don't do either, to the extent I need functionality from them. So I compared AHK and AI, and AHK does not even have real arrays, and ugly programming style, with all those rounded brackets. Furthermore, AI has much more commands, and I tried to write something in it, and it seems to be the right scripting language for me.

So what I want to do is this: I need to transpose all my current "macros" into AI, and on top of that, I want to write some additional scripts where I need a language like AI to realise what I want, and which are the reason I am coming here.

But now for my problem: I simply don't understand which way I could assign all those keyboard shortcuts to those multiple scripts!

In AHK, if I have understood AHK well, you have ONE big script which is loaded when you load AHK, and in which you do the key assignments first, then do the "functions" = little scripts, one by one, key a then triggering script x, key b triggering script y, key c triggering script z, and so on (and you can do lenghty scripts in additional files but the key assignments for them are in that main script).

But in AI, these key assignments I do not understand!

You can indeed run a script in which you do multiple key assignments, but then, this script will end, and then what?

I try to understand that you need (???) endless while loops with "sleep" for some milliseconds each: Is this in order to maintain this key assignment script running endlessly, so that any other script triggered by these assignments will indeed be triggered by pressing those keys / key combinations?

But this way, this key assignment script would endlessly interfere with any other program running, and even with those other AI scripts it triggers when you press the keys assigned in it to those scripts?

Is it not correct that this endless "sleep" loop in it will hinder other programs to run while this endless script is "sleeping"? So will this script not slow down your computer?

I am a non-programmer indeed, and that might be the reason why I do not understand what is going on there, or even how to do it: For example, the script should it "sleep" for 100 ms or less each time, in some examples I saw "sleeping" phases of just 10 ms, in others 1,000 ms! (I need those macros for office applications.)

At least, did I understand well, that sleep loop is for the script never running out except when closing down AI and / or the computer?

Please give me some insight and some advice, since I would really HATE to have to go back to AHK just for not knowing, all the less understanding, how to trigger my AI "macros"! (I need dozens of "macros" / scripts, and must trigger them any some seconds, so double clicking on the AI files would not be a solution.)

Thank you very much for your help!

Edited by Newtoai

Share this post


Link to post
Share on other sites



When you set a hotkeyset, it dosent need a loop of its own, nor does it have a lengthy sleep.

Its is just set to trigger a funtion in your script, whatever that script may be and whatever that function may be.

Welcome to the forums.


AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Ok well ill briefly explain how Sethotkey works,

Sethotkey ("{A}", "A" ) ; This creates a hotkey that will run a Function called 'A()'.

While 1
 Sleep (1000) ;Keeps script running
Wend

Func A() ;This script is activates when the A SetHotkey is triggered
 ;What you want this function to do
Endfunc

What this script does, it does nothing until the A Key is pressed and activates the A() Function.

Is it not correct that this endless "sleep" loop in it will hinder other programs to run while this endless script is "sleeping"? So will this script not slow down your computer?

The endless sleep function stops the script from finishing, if it finishes it cant respond to your hotkey requests. This means Every 1 Secound(1000ms) it will process functions put into the loop. If the sleep in this loop is too quick, it will process too fast and cause higher CPU useage. So Depending on the nature of the script depends on the sleep delay required for the task.

Ps. If this is in any way related to Game Automation, even if its very distant they will lock the thread. If that is what you need help with i suggest you ask people privately as its not aloud in the forums.

Edited by Orgasim

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

To JohnOne:

Thank you very much for your welcome. No pun intended, but I got into such lengths explaining my problem because, in fact,

"is just set to trigger a funtion in your script, whatever that script may be and whatever that function may be"

that part I had understood, without getting to the part how to have, in an acceptable way, a global shortkey system, like in any other "normal" macro program, that is, I was very aware of the fact that those key bindings would work in the given script, but then, how to trigger that given script in order for the bindings to work?! I was hoping to have overlooked something, since I could not believe this basic part of AI was so weird?! (I say this as a non-programmer, not knowing how other such programs work "behind the scenes".)

To Orgasim:

Thank you very, very much for your practical, constructive, really helpful approach basically confirming that yes, I had understood AI's (mal-?) functioning rather well (but then, without really realizing it could (mal- ?) function in such a weird (???) way; I was very much hoping to have misunderstood those backgrounds and came here to find some better solution.

But no, your post, for which I am really very grateful, seems to show that there isn't ?!

(Especially the part not to do the key bindings within the loop is very kind of you, even if I had understood that before, seeing some code snippets in game forums I had been directed to by my google search (see beneath!).)

But let me condense AI's problem as I see it:

To Orgasim and to everybody:

By not stopping this assignment script, it will interfere with every other program's claim for processor time, in the interval of 10, 100, 1,000 or any other given milliseconds. That way, OR it slows down your computer = those other programs it is intended to serve, not to slow down, OR (when the interfering interval is say 500 or 1,000 ms instead of 10 or 100) is cannot react in time to your key pressings it is intended to capture?!

How do other / traditional macro programs work behind the scenes? Perhaps this behaviour of AI which seems so weird to me, might be quite normal and ubiquitous, except for my not knowing it? So, a "sleep" of 100 ms would perhaps be a good compromise between "not-interfering" and "quite-good-reacting"?

So how do traditional macro programs work? Just the same, perhaps with reaction times of 50 ms ? I am putting the question because, after posting my first post here, I have been wondering if I should CONTINUE to use my CURRENT macro program (HotKeyboard) for all my "simple stuff" and to just TRIGGER SOME AI scripts where HotKeyboard reaches its limits (HotKeyboard can trigger programs and files, so it could trigger AI scripts)?!

But then, would this be a weird thing to do since HotKeyboard, and all other traditional macro programs, in fact perhaps work all the same way, by such sleeping loops?!

Now for the gaming question: In fact, I never did a computer game in my whole life, and I am 4 times older than those young people who are addicted to such games. But since I searched this forum (and others) for hours, I am very aware that the owners of this forum are really OBSESSED with possible mis-use of AI for gaming automation (and so, even your PS, Orgasim, was a very kind one, since you want me to avoid to being thrown out here, thank you very much for this care!).

But WHY this obsession with gaming automation? I said I do normal macro programming, for office programs... and then I suddenly understand why you don't believe me: MS Word, MS Excel and all those other ubiquitous office applications have IN-BUILT macro functionality, so why bother with external programs, and even, with AI, with external programming, right?!

Well, in my case, I use the standard office applications for exporting my data only, here and then, but I work with programs like MyInfo, askSam, Windows Internet Explorer 7, and need interaction between them, and need macros IN those programs... which have NO macro functionality and will perhaps never get one.

And I suppose many, many people out there are like me: They need macro functionality for OFFICE programs that are NOT Microsoft or OpenOffice. Could this explanation appease a little bit the forum's owners in their gaming automation obsession? Why do they bother? With or without AI, I will not play computer games, and people who do, let them program automation if they want to: At least THEN they do something that will prove useful for them in later life, while gaming will not, right? GAMING is a misuse of computers and of players' time, is it not? So the problem would be gaming, not gaming automation, or do I miss any important aspect there?

So again, would it be a good idea to just trigger, AI scripts for elaborated things, with HotKeyboard (or any other simple macro program), or would this be weird, since that always-running AI key bindings script would just do what every other traditional macro program would do (without my knowing) anyway?

Thank you very much for any real insight into these fundamental things!

Edited by Newtoai

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

I am not allowed any more to edit my post (why?), so I do an addition here:

And then, that always-running AHK script, perhaps it does exactly the same, but without "showing" it? (In fact it shows the key bindings, but without containing an explicit "sleep" loop or something like that.) And why is it that AHK people are not obsessed with gaming misuse of AHK scripts? Could it be that in AHK there is a standard, given sleeping loop of let's say 100 ms or so, while in AI you can tune this, down to 10 or 5 ms? And could it be that by this 5 ms loop possible in AI, AI is perfect for gaming automation, whilst AHK, with a mandatory 100 or 200 ms loop, is not??? Just an idea, but then, am I right?

Thank you very much for insight into and info on these fundamental things!

Edited by Newtoai

Share this post


Link to post
Share on other sites

OR (when the interfering interval is say 500 or 1,000 ms instead of 10 or 100) is cannot react in time to your key pressings it is intended to capture?!

HotKeySet will interrupt the "current" function so that wont happen if you code correctly.

Now for the gaming question: In fact, I never did a computer game in my whole life, and I am 4 times older than those young people who are addicted to such games. But since I searched this forum (and others) for hours, I am very aware that the owners of this forum are really OBSESSED with possible mis-use of AI for gaming automation (and so, even your PS, Orgasim, was a very kind one, since you want me to avoid to being thrown out here, thank you very much for this care!).But WHY this obsession with gaming automation?

Look at the "Old Gaming and 'Bots"-forum and you'll see why...

that always-running AHK script, perhaps it does exactly the same, but without "showing" it?

Probably.

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

JohnOne, AdmiralAlkex, please accept my gratitude for your kind help.

Have a look into the milenix.com forum (= for MyInfo), looking up "Fred", to be 100 p.c. sure you didn't help another one "no, I just want play for myself" game afficionado out there. The link is: http://www.milenix.com/forums/viewtopic.php?f=1&t=3435 and many other ones there, I'm doing serious stuff. Thank you again!

Edited by Newtoai

Share this post


Link to post
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
Sign in to follow this  
Followers 0