My experience porting AHK scripts to Linux.

Discuss other useful utilities, general computing tips & tricks, Internet resources, etc.
burque505
Posts: 1352
Joined: 22 Jan 2017, 19:37

Re: My experience porting AHK scripts to Linux.

08 May 2020, 07:55

@mfeemster, you might take a look at the code for sharpAHK by LucidMethod. There may be some code there that makes your work easier.
Regards,
burque505
mfeemster
Posts: 22
Joined: 24 Apr 2020, 18:30

Re: My experience porting AHK scripts to Linux.

09 May 2020, 22:25

Thanks, that looks rather interesting, although I'm not exactly sure what the intent is. Am I correct in thinking that it's not doing any type of parsing or running of scripts, but instead, it's taking various functionality that you'd see in scripts (and is implemented in C++ in AHK) and just providing that functionality in C#. Such as send a key, focus a window, etc...

The author, LucidMethod, appears to have worked on this project much more recently, unlike IronAHK which was abandoned years ago. Is LucidMethod on these forums?

If my assessment of his project is as I mentioned above, then perhaps I can use some of his code for executing various scripting functionality. IronAHK already has much of it done, but leaves many parts blank. Perhaps reconciling the two can give me more coverage. Regardless, much work remains.

Once I get to a point where I'm comfortable publishing it, I will make my own thread for it. I'd love to have as many people help out as possible.
burque505
Posts: 1352
Joined: 22 Jan 2017, 19:37

Re: My experience porting AHK scripts to Linux.

10 May 2020, 08:34

The only place I've seen LucidMethod active is on github, which you already know.

There are two ways to get AHK functionality with sharpAHK, it seems to me. One wraps a version of a wrapper around amazing-andrew's AutoHotkey.Interop, a wrapper of AutoHotkey.dll for interacting with AHK and embedding it in C# code, so you can create an instance of AutoHotkey.Engine - run AHK scripts, get and set variables from an instance, create a pipes handler, etc. The other (see the folder 'AutoHotkey.Interop'\_sharpAHK') can also call an AHK engine (see '_AutoHotkey.cs'), but in addition has (as you rightly suggest) AHK-like functionality in C#. (See e.g. '_Mouse.cs'; '_Clipboard.cs'.)

(I'm pretty fuzzy as to whether any of this C# functionality is in any way dependent on an instance of the Autohotkey engine, but at least some it is apparently not dependent on AHK at all.)

Looking forward to your code, @mfeemster!

Regards,
burque505
SOTE
Posts: 1055
Joined: 15 Jun 2015, 06:21

Re: My experience porting AHK scripts to Linux.

11 May 2020, 02:26

Belated welcome, and good to have you aboard, mfeemster.

I'm a bit confused by the conversation. My understanding is that wrapping the AutoHotkey.dll will not work on Linux, unless the intent is to use WINE. This might not be the path that one wishes to take, as one might want to be independent of WINE.

Also, it appears that IsNull helped out on the original IronAHK, and might still be active. It appears he was involved in the code for Linux too. He made various contributions on GitHub last year. https://github.com/IsNull

The Linux code appears under Rusty, for IronAHK on GitHub
https://github.com/Paris/IronAHK/tree/master/Rusty/Linux
mfeemster
Posts: 22
Joined: 24 Apr 2020, 18:30

Re: My experience porting AHK scripts to Linux.

11 May 2020, 15:32

Hi @SOTE , thanks for the welcome.

I have all of the IronAHK code and have mostly made sense of it.

I will check out that IsNull person if I get stuck.

I am indeed trying to make something independent of WINE. My intent is to pick up where IronAHK left off and expand it, while also doing a few things differently. I'll detail the differences in the future after I have something to present.

That said, I am stuck on the concept of "variables" in AHK. Not sure if this is the proper thread to ask it on. If not, let me know where.

Being a senior developer, variables always have a type. However, in AHK, their type seems to be indeterminate. It's sort of a string, but sort of an int, sort of a float, but that one isn't a string, and they might work with COM, but also might not. Ugh!

>>> Although a variable is typically thought of as holding a single value, and that value having a distinct type (string, number or object), AutoHotkey automatically converts between numbers and strings in cases like myString + 1 and MsgBox %myNumber%. As these conversions can happen very frequently, whenever a variable is converted, the result is cached in the variable.

In effect, a variable can contain both a string and a number simultaneously. Usually this just improves the script's performance with no down-sides, but if a variable contains both a number and a string, is it number, or is it a string? This ambiguity causes unexpected behavior in at least two cases:
1.COM objects. In order to pass parameters to a COM object, the program must convert the variable's content to either a number or a string. Some COM objects throw an exception if the wrong type of value is passed. If a variable has both, the number is used. Usually this gets the right result, but sometimes it doesn't.
2.Objects don't have the capability to store both a number and a string as a key or value. Since numbers are more memory-efficient, if a variable has both, the number is used (except for floating-point values used as keys).

SetFormat's slow mode forces the assignment of a pure number to immediately convert that number to a string. For integers, the number is also stored, so this doesn't have adverse effects other than to performance. For floats, the number is not stored, since SetFormat affects the precision of the value, possibly even truncating all decimal places. In other words, SetFormat's slow mode prevents pure floats from being stored in variables.

Taking the address of a variable effectively converts the variable's value to a string, disabling caching until the variable's address changes (this happens when its capacity changes). This is both for backward-compatibility and because the script could change the value indirectly via its address at any time, making the cache inaccurate.

---------------------------------------------------

So let me ask about the following scenarios.

Say you have a function:

Func(x, y)
{
z := x + y
}

How does it know what to do in the following cases:

Func("hello", 1)//Adding 1 to a string makes no sense
Func(1, 2)//Ok
Func(true, false)//Also makes no sense
Func("hello", true)//Ditto


You see my point. Without any way for the script to specify the type, it's very hard for me to know what *should* be done under the covers, when porting this to C#. As you know in C#, object is the base of everything. But that still doesn't solve this problem.

Any help or direction would be much appreciated.

Thanks.
mfeemster
Posts: 22
Joined: 24 Apr 2020, 18:30

Re: My experience porting AHK scripts to Linux.

11 May 2020, 15:54

I've further inspected both the AHK and IronAHK code and see how they do it. Horribly inefficient, but it looks like the only way.
mfeemster
Posts: 22
Joined: 24 Apr 2020, 18:30

Re: My experience porting AHK scripts to Linux.

12 May 2020, 17:03

A moderator named BoBo just sent me a PM and I can't reply to him.

BoBo: if you see this, can you please enable the reply feature on my account? Thank you.
BoBo
Posts: 3617
Joined: 13 May 2014, 17:15

Re: My experience porting AHK scripts to Linux.

13 May 2020, 08:34

@mfeemster I've changed your status. Please check if you have access now, and good luck with finding some allies so ironAHK will rise like a Phoenix :thumbup:
mfeemster
Posts: 22
Joined: 24 Apr 2020, 18:30

Re: My experience porting AHK scripts to Linux.

13 May 2020, 10:54

@BoBo Thanks, but it still won't let me reply to your message, or compose a new PM to you.
BoBo
Posts: 3617
Joined: 13 May 2014, 17:15

Re: My experience porting AHK scripts to Linux.

13 May 2020, 11:04

mfeemster wrote:
13 May 2020, 10:54
@BoBo Thanks, but it still won't let me reply to your message, or compose a new PM to you.
Our fellow moderator @gregster (or another of our guardian angels :angel: ) might shed some light on this (restriction). Stay tuned.
gregster
Posts: 4908
Joined: 30 Sep 2013, 06:48

Re: My experience porting AHK scripts to Linux.

13 May 2020, 15:12

BoBo wrote:
13 May 2020, 11:04
mfeemster wrote:
13 May 2020, 10:54
@BoBo Thanks, but it still won't let me reply to your message, or compose a new PM to you.
Our fellow moderator @gregster (or another of our guardian angels :angel: ) might shed some light on this (restriction). Stay tuned.
Did you check after your last post? You should be pretty close to the threshold.
mfeemster
Posts: 22
Joined: 24 Apr 2020, 18:30

Re: My experience porting AHK scripts to Linux.

13 May 2020, 21:33

Yes, I can send PMs now. Thank you.
rbreaves
Posts: 1
Joined: 12 Jun 2020, 16:48

Re: My experience porting AHK scripts to Linux.

12 Jun 2020, 17:21

You guys might be interested in looking at the xkeysnail project as well, it has got to have the simplest and closest autohotkey like implementation I have seen, but written in python. The syntax is python, but for me it has worked equally well for most things I have thrown at it (although I need to submit some new PRs to fix some scenarios I might have broken).

https://github.com/mooz/xkeysnail

My own remapping project that uses both autohotkey and xkeysnail is located here https://github.com/rbreaves/kinto for anyone that wants to check it out. It would definitely be awesome to have autohotkey in linux though.

Wayland will be another ball game though compared to x11. I have done some early work on it though.

https://gist.github.com/rbreaves/257c3edfa301786e66e964d7ac036269

And a mention by this guy who updated an x11 app to work under wayland if it is running Gnome.
https://github.com/ActivityWatch/activitywatch/issues/92#issuecomment-642030180

I believe the same could be done for a python implementation such as xkeysnail or potentially a rewrite of ahk.

Return to “Other Utilities & Resources”

Who is online

Users browsing this forum: No registered users and 3 guests