[FYI]: Using SendMessage with AutoIt

English support forum

Moderators: white, Hacker, petermad, Stefan2

icfu
Power Member
Power Member
Posts: 6052
Joined: 2003-09-10, 18:33 UTC

[FYI]: Using SendMessage with AutoIt

Post by *icfu »

First I thought it was possible, then I learned it was not, now I found it's indeed possible using DllCall:
http://www.autoitscript.com/autoit3/docs/functions.htm
http://www.autoitscript.com/autoit3/docs/functions/DllCall.htm

Example to show the about box:

Code: Select all

$hwnd = WinGetHandle("Total Commander")
DllCall("user32.dll", "int", "SendMessage", "hwnd", $hwnd , "int" , 1075 , "int", 690 )
1075 is WM_USER+51
690 is taken from totalcmd.inc

@SanskritFritz:
As you are experienced with AutoHotkey maybe you can tell your opinion about the approach here. To me it looks more powerful if dlls can be loaded, is that correct or am I wrong? Is it possible in AutoHotkey, too?

Icfu
This account is for sale
User avatar
SanskritFritz
Power Member
Power Member
Posts: 3693
Joined: 2003-07-24, 09:25 UTC
Location: Budapest, Hungary

Post by *SanskritFritz »

Thanks for the info!
AutoIt3 is in many ways better and above all much more consistent in its syntax, than AutoHotkey. And then also look what they have done with the Scite editor, amazing. I like AHK better because the hotkey and autotext support, which is inevitable for me. About the difference in stability and memory consumption i cannot tell much, but AHK has been proved very stable and very fast here. In AutoIt AFAIK you cannot do tricks like this or this very simple task:

Code: Select all

; Alt-Shift-W (Activate Total Commander)
!+w::WinActivate ahk_class TTOTAL_CMD
The one thing many people in the AHK community (including myself) miss very much, is indeed the direct calls to dll-s ;-)
The good news is, that it is planned and knowing the authors speed I hope this improvement for the near future. It is really a powerful option in a script, way better than only sending messages (as you showed, it is included).
I switched to Linux, bye and thanks for all the fish!
icfu
Power Member
Power Member
Posts: 6052
Joined: 2003-09-10, 18:33 UTC

Post by *icfu »

AutoIt3 is in many ways better and above all much more consistent in its syntax, than AutoHotkey.
I think so, too.
And then also look what they have done with the Scite editor, amazing.
I have tried SciTE in the past but wasn't too excited about it because by default useful things were set to off, like tabs and stuff like that and the editing of ini files to set all options wasn't too convenient. Maybe I will give it another try soon.

Here is your hotkey example with AutoIt3:

Code: Select all

AutoItSetOption("WinTitleMatchMode", 4)

Func activate_tc()
WinActivate("classname=TTOTAL_CMD")
EndFunc

While 1
HotKeySet ( "!+w" , "activate_tc" )
WEnd
Works flawlessly, Alt-Shift-W activates TC by classname.

What is "autotext"? Haven't found any info about that on a quick look but my guess is that it will be probably possible with AutoIt3, too. ;)


Thanks for you answer.

Icfu
This account is for sale
User avatar
SanskritFritz
Power Member
Power Member
Posts: 3693
Joined: 2003-07-24, 09:25 UTC
Location: Budapest, Hungary

Post by *SanskritFritz »

Now I start to really appreciate this thread! :-)

AutoIt3's Scite is an own editor based on Scintilla.
EDIT: oops, wrong, it is Scite, spiced up with AI3 definitions for syntax hiliting, folding, code completion, compiling and so on. But basically it is Scite, with all of it's flaws and annoyances ;-) havent used it much tho.

I didn't know AutoIt3 supports hotkeys! But this example you gave uses 100% processortime (I tried it) because of polling in the 'while' cycle. AHK consumes virtually no processortime, it hooks into the keyboard. A much better approach IMHO. The problem with AI3 is, that scripts cannot be persistent, meaning, they stay in memory ready to act on a hotkey or hotstring. If that would be possible in AI3 the way AHK does it (speed, speed!!), I would seriously consider a switch to AI3.

Autotext is simply what autocorrect is in Word. Well... a little more, but basically it is.
I switched to Linux, bye and thanks for all the fish!
icfu
Power Member
Power Member
Posts: 6052
Joined: 2003-09-10, 18:33 UTC

Post by *icfu »

Oops, I haven't checked the CPU cycles, made the example just as a quick hack. For sure there are better ways, it's just too overwhelming to see and get used to all those commands at first. ;)

Icfu
This account is for sale
User avatar
SanskritFritz
Power Member
Power Member
Posts: 3693
Joined: 2003-07-24, 09:25 UTC
Location: Budapest, Hungary

Post by *SanskritFritz »

Icfu wrote:
AutoHotkey scheint mir doch weiter entwickelt zu sein, auch wenn es offenbar vom "alten" AutoIt2 vieles übernommen hat.
In fact, AutoHotkey comes directly from AutoIt2 and is almost fully backwards compatible with it.
I switched to Linux, bye and thanks for all the fish!
User avatar
SanskritFritz
Power Member
Power Member
Posts: 3693
Joined: 2003-07-24, 09:25 UTC
Location: Budapest, Hungary

Post by *SanskritFritz »

icfu wrote:Oops, I haven't checked the CPU cycles, made the example just as a quick hack. For sure there are better ways
Please let me know if you find something, I really think AI3 is much less elaborate than AHK ;-) if it had the functionality, I'd switch to it.
[/url]
I switched to Linux, bye and thanks for all the fish!
icfu
Power Member
Power Member
Posts: 6052
Joined: 2003-09-10, 18:33 UTC

Post by *icfu »

Simple solution, sleep instead of loop:

Code: Select all

AutoItSetOption("WinTitleMatchMode", 4) 

Func activate_tc() 
WinActivate("classname=TTOTAL_CMD") 
EndFunc 

HotKeySet ( "!+w" , "activate_tc" ) 
sleep(2147483647)
CPU cycles = 0. :)

I don't think that in your example above a keyboard hook is used, see here:
http://www.autohotkey.com/docs/commands/_InstallKeybdHook.htm (Edit: Link corrected)
http://www.autohotkey.com/docs/commands/_Persistent.htm

The consumed memory raises when I add #InstallKeybdHook to your script. I think that AHK uses sleep command (make it resident) by default when hotkeys are used and it has nothing to do, AI instead exits the script by default, maybe this can be changed.

I have to read more to find out, it's just a guess. ;)

Icfu
Last edited by icfu on 2005-03-19, 01:54 UTC, edited 1 time in total.
This account is for sale
User avatar
SanskritFritz
Power Member
Power Member
Posts: 3693
Joined: 2003-07-24, 09:25 UTC
Location: Budapest, Hungary

Post by *SanskritFritz »

:lol: woa, what a solution! I will try this out. BTW I have to restart the script after 248 days! ;-)
About the hooks, you are right, AHK definitely uses sleep.

You really start to persuade me :-)

Any clues about hotstrings?
I switched to Linux, bye and thanks for all the fish!
icfu
Power Member
Power Member
Posts: 6052
Joined: 2003-09-10, 18:33 UTC

Post by *icfu »

BTW I have to restart the script after 248 days!
24,86 days. ;)
You really start to persuade me
Any clues about hotstrings?
Don't wanna persuade you, you are more experienced than me with scripting stuff. I have had no clue about all that till yesterday. ;)

Hotstrings I haven't found.

Icfu
This account is for sale
User avatar
SanskritFritz
Power Member
Power Member
Posts: 3693
Joined: 2003-07-24, 09:25 UTC
Location: Budapest, Hungary

Post by *SanskritFritz »

24,86 days.
Oops, right, i thought first, a second has 100 msecs :oops:

After experimenting a little with AutoIt3, and trying to migrate my AutoHotkey scripts to AI3, here are my remarks:

- Although AI3 supports hotkeys, it is very limited compared to AHK. AI3 uses only the windows API function RegisterHotkey(), AHK too, but is able to use keyboard hooks, which made it possible to implement hotstrings or even using keys like Ctrl itself, to modify certain behaviours in some windows (and yes, I do use hotkeys like CapsLock+LButton, the CapsLock has otherwise no use for me, it is just annoying, when I accidentally press it, so why not completely turn it off and use for something useful?). AHK seems to have "total control" as its goal.
- As already mentioned, AHK is able to use hotstrings, which (when using it wisely) can make life much easier and convenient. Typically i use it to expand abbreviations (even depending on the active window!), and autocorrect typos I often make.
- The way hotkeys are defined in AHK is more flexible than in AI3, consider this example: I want to have a hotkey only in TC, but "let it go through" to achieve the original functionality everywhere else.

Code: Select all

; Ctrl-G (Total Commander: splitter menu)
~^g::
	IfWinActive ahk_class TTOTAL_CMD
		ControlClick TPanel2, A,,RIGHT
	Return

Code: Select all

; Ctrl-G (Total Commander: splitter menu)
AutoItSetOption("WinTitleMatchMode","4")
HotKeySet( "^g", "TC_splitter_menu")
Func TC_splitter_menu()
	HotKeySet( "^g" )
	Send( "^g" )
	If WinActive( "classname=TTOTAL_CMD") Then
		ControlClick( "", "", "TPanel2", "right" )
	EndIf
	HotKeySet( "^g", "TC_splitter_menu")
EndFunc
- AI3 is a full fledged scripting language, much more suitable to write complex and structured scripts. The Scite4AutoIt editor is an amazing tool, making writing of a script as comfortable as in Delphi. An I love that code folding! In contrast, AHK's syntax is ridiculously awkward and inconsistent, variables are all global, no functions can be defined (but it can be simulated with a global ret_val variable, but this is dangerous when having more threads), no arrays can be defined (actually a simulation of an array is possible like var1, var2 etc., some AHK funtions create lists like this).
- AI3 has the ability to call DLL functions, that is a very powerful feature. But this is planned for AHK as well, and as we know, sending messages to controls is already possible (this is suitable for most "hacking" tasks).
- In AI3 an even more powerful ability will be implemented in the near future: the ability to register my scripts as ActiveX or in a DLL! This will allow me to call my scripts from WSH or Delphi.
- AHK has a nice GUI designer written entirelly in AHK (!). I haven't seen similar for AI3, but I wouldn't be surprised if I just overlooked it. On the other hand, AI3's GUI seems to be more advanced, it has more controls and more flexibility. I did not dig into the details nor in AHK or in AI3.

Personal conclusion:
As for me, I mainly use AHK to modify or add to the basic behaviour of some windows or applications, I'm not writing complex scripts (with complex i mean multiple calling of functions, and subroutines several pages long), even though it is very much possible. Hotstrings are ineviteable for me, i am so much used to them, that i have a hard time using another computer without AHK (before AHK i used MacroExpress). So, for me it looks like i will stick to AHK, with all my struggles with the structure and syntax :-(. I would like to see both of AI3's and AHK's improvements to AI2 in one product ;-)
I switched to Linux, bye and thanks for all the fish!
icfu
Power Member
Power Member
Posts: 6052
Joined: 2003-09-10, 18:33 UTC

Post by *icfu »

I would like to see both of AI3's and AHK's improvements to AI2 in one product
Well, I would like to see that, too, and I completely agree that the language structure of AHK just sucks because it is derived from AutoIt2.
I think this will mean that we just have to wait for AutoIt3 implementing the few additional features that AHK has compared with AI3. Maybe you can convince AHK authors to switch to the new AutoIt3 syntax and drop that old one?

I think it's neither good for beginners (like me) to learn some unstructured "language" first nor is it convenient for pros coming from other languages. But you are right that it's very powerful if you limit its use to smaller scripts, this way you can simply ignore its lacks. ;)

Meanwhile I checked the AI3 SciTE edition and I am amazed by its power. I think if I ever will start to "really" program I will use that one for sure. The speed of the Scintilla component is impressive, it can even be used as a small notepad replacement because it's so incredibly fastly loaded and responsive.

Icfu
This account is for sale
User avatar
SanskritFritz
Power Member
Power Member
Posts: 3693
Joined: 2003-07-24, 09:25 UTC
Location: Budapest, Hungary

Post by *SanskritFritz »

Maybe you can convince AHK authors to switch to the new AutoIt3 syntax and drop that old one?
Read this, it is interesting ('Jon' is the author of AI3, 'cmallett' is the AHK author)
The speed of the Scintilla component is impressive
Yeah, nothing bloated there, all customisation is done in textfiles ;-)
I think it's neither good for beginners (like me) to learn some unstructured "language" first nor is it convenient for pros coming from other languages. But you are right that it's very powerful if you limit its use to smaller scripts, this way you can simply ignore its lacks.
Fully agree!
I switched to Linux, bye and thanks for all the fish!
icfu
Power Member
Power Member
Posts: 6052
Joined: 2003-09-10, 18:33 UTC

Post by *icfu »

Very interesting quarrel there but too bad that they don't bundle their efforts, what a waste of time and energy.

I strongly disagree here with the second part of the following quote from cmallett:
I consider AutoIt3 to be a vastly more powerful and flexible language than the primitive AutoHotkey. However, that power and flexibility does come at a cost: I think you'll admit that AutoIt3 is slightly harder to learn and remember than AutoIt2.
I think it's way harder to learn languages without syntax or bad syntax than one with well structured syntax even if the code "looks" more complicated, it definetely is not.

In the hotkey example this is pretty obvious:
In AI3 hotkeys are separated from the functions they call, if you want to change a hotkey you only need to look thru a small part of the source code, in AHK hotkey and function is bound together which is a real mess.

Somehow AHK is as messy as TC concerning hotkeys and such and AI3 is more like the unified command system approach that would bring structure and logic to all that... ;)

Icfu
This account is for sale
User avatar
SanskritFritz
Power Member
Power Member
Posts: 3693
Joined: 2003-07-24, 09:25 UTC
Location: Budapest, Hungary

Post by *SanskritFritz »

I fully agree with all you said. Especially:
too bad that they don't bundle their efforts, what a waste of time and energy.
traurig :-( Just imagine what a great product i could be if they merged AI3 and AHK!
I switched to Linux, bye and thanks for all the fish!
Post Reply