hello world automation on Linux/Mac/iOS/Android

Talk about anything
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

hello world automation on Linux/Mac/iOS/Android

07 Mar 2019, 00:48

- People talk about porting AutoHotkey or equivalent functionality to other systems, but nothing ever happens.
- I could work on it from time to time, or assist, but I'd need to get a foothold.
- Classic functionality would be to retrieve the window title, and text, in Notepad, or the Notepad equivalent.
- In the example below I show how to do this in Notepad via AutoHotkey commands, and then via the DllCall function (the DllCall code can be easily translated into C++).
- I would greatly appreciate if others could provide similar code, in any programming language, for other systems (e.g. Linux/Mac/iOS/Android).

- Other basic examples would be appreciated also, such as sending key presses and clicks. And the fundamental example for creating hotkeys: receiving key presses.
- Also, examples of existing programs with any of this functionality would be much appreciated, especially if they are open source.
- And, any examples of window inspectors such as AccViewer (for Windows) would be useful, to get an idea of what text can be retrieved from windows/GUIs.
- Thanks.

Code: Select all

q:: ;Notepad - get window title and Edit control text
;get title/text using built-in commands
WinGetTitle, vWinTitle, A
ControlGetText, vText, Edit1, A
vOutput1 := vWinTitle "`r`n" vText

;get title via DllCall
hWnd := DllCall("user32\GetForegroundWindow", "Ptr")
vChars := 1+DllCall("user32\GetWindowTextLength", "Ptr",hWnd)
VarSetCapacity(vWinTitle, vChars*2, 0)
DllCall("user32\GetWindowText", "Ptr",hWnd, "Ptr",&vWinTitle, "Int",vChars)
VarSetCapacity(vWinTitle, -1)

;get text via DllCall
vCtlID := 15 ;Edit control
;vCtlID := 1025 ;msctls_statusbar32 control
hCtl := DllCall("user32\GetDlgItem", "Ptr",hWnd, "Int",vCtlID, "Ptr")
vChars := 1+DllCall("user32\SendMessage", "Ptr",hCtl, "UInt",0xE, "UPtr",0, "Ptr",0, "Ptr") ;WM_GETTEXTLENGTH := 0xE
VarSetCapacity(vText, vChars*2, 0)
DllCall("user32\SendMessage", "Ptr",hCtl, "UInt",0xD, "UPtr",vChars, "Ptr",&vText, "Ptr") ;WM_GETTEXT := 0xD
VarSetCapacity(vText, -1)
vOutput2 := vWinTitle "`r`n" vText

MsgBox, % vOutput1
vScriptName := A_ScriptName
DllCall("user32\MessageBox", "Ptr",0, "Ptr",&vOutput2, "Ptr",&vScriptName, "UInt",0)
return
==================================================

LINKS (LINUX) (IRONAHK)

GitHub - Paris/IronAHK: Cross platform .NET rewrite of the popular AutoHotkey scripting language for desktop automation.
https://github.com/Paris/IronAHK
IronAHK - .NET port of AutoHotkey for Windows, Linux, Mac... - Offtopic - AutoHotkey Community
https://autohotkey.com/board/topic/31480-ironahk-net-port-of-autohotkey-for-windows-linux-mac/
IronAHK (alpha): cross platform .NET rewrite of AutoHotkey - Scripts and Functions - AutoHotkey Community
https://autohotkey.com/board/topic/50354-ironahk-alpha-cross-platform-net-rewrite-of-autohotkey/
naming conventions - Why are many ports of languages to .net prefixed with 'Iron'? - Stack Overflow
https://stackoverflow.com/questions/1194309/why-are-many-ports-of-languages-to-net-prefixed-with-iron
IronAHK still a thing? - Utilities - AutoHotkey Community
https://autohotkey.com/board/topic/102633-ironahk-still-a-thing/

LINKS (LINUX)

Linux AutoHotkey version - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=13&t=12971
We want AHK for Linux! - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=13&t=60112
Autohotkey like function for Linux - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=81&t=64772
Another alternative to AHK for Linux / Unix - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=22&t=17630
Replicating AutoHotKey's magic on a linux/unix/mac osx computer (thoughts on linux/osx port?) - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=22&t=9806
AHK alternative for Ubuntu? - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=22&t=3685
AHK in Linux? - Offtopic - AutoHotkey Community
https://autohotkey.com/board/topic/4157-ahk-in-linux/
My experience porting AHK scripts to Linux. - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=22&t=65552

==================================================

LINKS (MAC/IOS)

Can I run AHK on a Mac that is running Windows with Parallels? - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=19244
Autohotkey for Mac - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=27043
AutoHotKey Equivalent for Mac - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=23&t=35638
Writing AHK Interpreters for Mac - Any plans for the future / current projects? And other Qs... - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=62690

==================================================

LINKS (ANDROID)

Ahk Text expansion on Android? - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=66383
Last edited by jeeswg on 02 Dec 2019, 22:47, edited 4 times in total.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
davebrny
Posts: 85
Joined: 05 Dec 2016, 06:26

Re: hello world automation on Linux/Mac/iOS/Android

18 Jun 2019, 16:57

i was messing around with ahk in wine a few days ago and im just searching to see what other people have done. have you managed to figure out much since you posted this?

a lot more is working than i expected anyway. mouse move, menus, hotkeys, fileselect, run command, passing parameters to a second script, tooltips, traytips (but the bottom is cut off slightly). theres still a lot of other things to try though.

those two msgBox's work ok as well and they show the title and text from notepad no problem. although it only shows window titles from inside the wine container unfortunately.... its slowly starting to make more sense now that im getting my head around what wine actually is. i was imagining at first that if you could get ahk running you could use it to control some other things on linux but it looks like its going to be very limited in what you can do. but i havnt really spent enough time with it to know for sure yet and i suppose it depends on what you are trying to achieve

one good thing is that it looks like you can put all your scripts into the the documents folder on linux and have them be accessible from within each wine container, so at least you dont have to make multiple copies of your scripts for each container
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: hello world automation on Linux/Mac/iOS/Android

18 Jun 2019, 17:46

To reiterate the OP, I'm looking for info on the Linux/Apple/Google equivalents to the Windows API, as I don't use those systems. Info would be good, not even any code. E.g. how to:
- get active window title
- get active control text
- send key presses
- send clicks
- detect key presses (to trigger hotkeys)
- window inspector tools (get info from windows)

WINE isn't really a different API, but seeks to reverse-engineer the Windows API. (Although being able to use Windows programs/AHK on Linux would be useful.) Are there any key things not working? Could you explain more how you got it working, either here, or perhaps better in a separate thread (which you could link to here).
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
SOTE
Posts: 1426
Joined: 15 Jun 2015, 06:21

Re: hello world automation on Linux/Mac/iOS/Android

20 Jun 2019, 00:13

Someone else made a post, referring to their experience with using AHK, Linux, and WINE.
https://www.autohotkey.com/boards/viewtopic.php?f=22&p=281494#p281494
User avatar
davebrny
Posts: 85
Joined: 05 Dec 2016, 06:26

Re: hello world automation on Linux/Mac/iOS/Android

24 Jun 2019, 09:39

jeeswg wrote:
18 Jun 2019, 17:46
To reiterate the OP, I'm looking for info on the Linux/Apple/Google equivalents to the Windows API, as I don't use those systems
doh. i just saw linux in the title and thought you were talking about wine. ill get my coat
jeeswg wrote:
18 Jun 2019, 17:46
Are there any key things not working? Could you explain more how you got it working, either here, or perhaps better in a separate thread (which you could link to here).
i havnt gone through every key or key combination yet but most that i tried seem to be working anyway. the only ones i had a problem with were alt with a regular key, which would only work if i used the #UseHook directive... but then alt with other modifiers stop working so i decided to leave it off.

there actually wasnt much to getting it running in the end. just type "winecfg" into the terminal to create the wine folder in your home directory. put your scripts and the portable version of autohotkey anywhere inside the c drive folder, then run this command:

Code: Select all

wine "full_path_to_AutohotkeyU32.exe" "full_path_to_script.ahk"
the full path looks something like this: /home/dave/.wine/drive_c/users/dave/My Documents/script.ahk

thats the main jist of it anyway but yea i might write up a separate post because there are a few other things you can do to make the whole process a bit easier

SOTE wrote:
20 Jun 2019, 00:13
Someone else made a post, referring to their experience with using AHK, Linux, and WINE.
https://www.autohotkey.com/boards/viewtopic.php?f=22&p=281494#p281494
thanks very much sote! i missed that post somehow when i was searching the forums
SOTE
Posts: 1426
Joined: 15 Jun 2015, 06:21

Re: hello world automation on Linux/Mac/iOS/Android

24 Jun 2019, 19:43

I'm wondering if AutoHotkey can be used with WINE, then have a special library specifically for Linux and the macOS. To possibly include Android. The special libraries would have functions that handle Linux and macOS GUIs, to include other differences between the languages.

I think a fork of AutoHotkey written in C# (possible restart of IronAHK) or possibly Object Pascal would arguably be a more ideal situation, because these programming languages lend themselves more to being cross-platform. But such a fork would be no small feat, as AutoHotkey has a lot of code and features from over the years. Though the fork could initially limit the scope of what it's trying to accomplish at first. However, considering that multi-language developers willing to make such a fork is apparently non-existent to hard to come by, using WINE might be the only realistic choice for now.

In the case of AutoHotkey and WINE, advanced users might be able to contribute the needed libraries and classes for the additional functionality in Linux, macOS, and Android (though that's likely to a bit harder nut to crack). WINE can also run on Androids, but to attempt to use Windows applications, you will need an Android device that runs a x86 CPU and not ARM. And it's not clear how well that WINE will run Windows apps on the Android. Linux and the macOS might prove a bit easier.

The other thing about WINE, is there will be additional steps that must be done, if giving out or making AutoHotkey scripts available on other OSes. You can't simply compile a script and tell people on those OSes to use it. You must get users to install and setup WINE first, prior to using AutoHotkey on that OS. I know a lot of people will have Android smartphones, in addition to Windows computers. Looking at it, AutoHotkey and WINE on x86 Androids seems like it will take some tinkering. For individuals, WINE might work as a solution. Not sure about it as a solution for multiple computers on a network, such as in a business or school, but maybe if a group of people go down this direction there will be more solutions. To include dedicated threads showing how tos and solving issues of AutoHotkey on WINE.

Also, I want to clarify the difference between the automation of GUIs in a particular OS and the running of applications written in AutoHotkey. One might be easier than the other, depending on how a person wrote their AutoHotkey application and what functions/libraries it's using.
SOTE
Posts: 1426
Joined: 15 Jun 2015, 06:21

Re: hello world automation on Linux/Mac/iOS/Android

25 Jun 2019, 00:23

In looking at AutoHotkey on the WINE website, there looks to have been an alternate AutoHotkey version compiled with GCC, instead of Visual Studio. GCC might open up more options... This version was called AutoHotkeyx.

AutoHotkeyX on WINE
https://appdb.winehq.org/objectManager.php?sClass=version&iId=17738

Tinku99 GitHub with AutoHotkeyX (ahkx) files.
(includes source code written in C)
https://github.com/tinku99/ahkx?files=1

xdotool
https://github.com/jordansissel/xdotool

Return to “Off-topic Discussion”

Who is online

Users browsing this forum: No registered users and 60 guests