AutoHotkey v3.0-alpha.1 - Switching to JavaScript (not really)

Community news and information about new or upcoming versions of AutoHotkey
lexikos
Posts: 9583
Joined: 30 Sep 2013, 04:07
Contact:

AutoHotkey v3.0-alpha.1 - Switching to JavaScript (not really)

Post by lexikos » 31 Mar 2021, 17:03

[Edit on 02 April 2021: See page 2 for clarification.]

I have decided to bring the seemingly endless development of AutoHotkey v2 alpha to a close. It has been almost exactly 10 years since the release of v2.0-a001. My interest in AutoHotkey development has dropped off repeatedly, and there have been times I've decided to officially retire from the community, maybe handing over the lead to someone else. But lack of motivation caused inaction at all levels, and here I still am.

In the meantime, other scripting and programming languages have made interesting developments. Mainstream languages tend to have considerably more developers driving them, larger communities, and more learning resources. To keep AutoHotkey alive long term, I think it best that the program's core functionality be decoupled from its unique scripting language, and be made available to mainstream scripting and programming languages.

With that in mind, AutoHotkey v3.0-alpha.1 implements JavaScript in place of AutoHotkey's original language (which I've always thought of as unnamed). I chose JavaScript because Windows 10 includes a reasonably modern JavaScript engine (the one used by legacy Edge) with a very easy to use hosting API. Although legacy Edge has been discontinued, development continues on the open source ChakraCore engine. Future builds will optionally utilize ChakraCore.

Most functions from v2.0-a129 are available (but not all tested), including:
Spoiler

Because JavaScript has no language feature equivalent to ByRef, the following functions return an object with a property for each output parameter (which should be omitted from the parameter list when calling the function):
Spoiler

The following functions are excluded because they are redundant or AutoHotkey-specific:
Spoiler

Most built-in variables are available. These are not: A_IsCritical, A_Index, A_Loop..., A_Space, A_Tab, A_ThisFunc

These classes are available: ClipboardAll, File, Gui, InputHook, Menu, MenuBar


Loops

Loop Parse has no replacement; JavaScript has enough ways to parse strings. Loop Files and Loop Reg are replaced with functions which accept a callback. Ideally they would be replaced with functions which return an iterator (to use with for (x of y)), but the nature of their implementation makes that difficult.

loopFiles(pattern, mode, callback);
loopFiles(pattern, callback);
callback(file) is called for each file. file has the following properties: attrib, dir, ext, fullPath, name, path, shortName, shortPath, size, timeAccessed, timeCreated, timeModified

loopReg(keyName, mode, callback);
loopReg(keyName, callback);
callback(regItem) is called for each key or value. regItem has the following properties: name, type, key, timeModified


Directives

Supported directives are translated to either a function or a property. Some are not relevant, not implemented, or already had equivalent functions in AutoHotkey. The rest are described below.

include(path);
Evaluates the file in global scope, at run time. There is no *i option, but try-catch can be used, and it can be called conditionally, like any other function. As with #Include, it has no effect if called a second time for the same path (which is resolved to a full path and case corrected internally).

installKeybdHook();
installMouseHook();
persistent();
Direct replacements for the corresponding directives.

singleInstance(mode);
Scripts are not single-instance by default, as the script needs to run in order to override default behaviour. singleInstance(mode) accepts the case-insensitive mode strings 'force' (the default if omitted), 'ignore' and 'prompt'.

hotkey.inputLevel
hotkey.maxThreadsBuffer
hotkey.maxThreadsPerHotkey
hotkey.useHook
These properties directly replace the corresponding directives; of course, being properties and not directives, their values can be retrieved or changed at runtime. As before, these settings only affect the default options for newly created hotkey variants.


Other Additions

collectGarbage();
Takes out the trash immediately (but usually the trash takes itself out anyway).


Using the Program

How to run, mostly as before:
  • Drag-drop a script onto the exe.
  • Run the exe directly; running AutoHotkey32.exe will load AutoHotkey32.jk (or js) if present; otherwise it will show a file selection dialog. The default script name depends on the exe name, as before, so you may rename the exe if you wish to have it run something else by default.
  • Use the command line as before (but /Debug and /validate are not implemented).

General Remarks

The current JavaScript runtime has some limitations:
  • It requires Windows 10.
  • Attempting to load the older JScript engine used by IE11 (such as with a WebBrowser ActiveX control) may cause the program to become unstable. I think this is because Microsoft does not support loading both chakra.dll and jscript9.dll into one process.
  • ES6 modules are not supported.
Implementing ChakraCore might lift these limitations.

Function names are in lower camel case, while classes and built-in variables are in upper camel case (a.k.a. PascalCase).

Use A_IconHidden = false in place of #NoTrayIcon. The icon is not shown if this is used within 100ms of starting the script.

JavaScript destructuring assignments can be used with functions which return an object; e.g. let {x, y} = mouseGetPos();.

Instead of a Buffer, use a JavaScript ArrayBuffer, typed array or DataView.

DllCall and ComCall are available and mostly unchanged, but may be unsafe with regard to pointers on x64, as JavaScript does not support the full 64-bit integer range. Output parameters are not fully implemented, but ptr parameters can be used instead (e.g. with a single-element typed array such as new Uint32Array(1)).

Support for promises/async/await is not yet implemented.


Download

Note: The included script registers or unregisters the .jk file type with the current exe, for extremely simple setup. Run AutoHotkey32.exe, or drag-drop AutoHotkey32.jk onto AutoHotkey64.exe to register with that exe.


Examples

Simple hotkey
Simple hotkey with reusable function
Simple hotstring
loopReg
Gui and loopFiles
Clipboard hotkey "factory" function using closures

laozhhaiJohn
Posts: 24
Joined: 20 Mar 2021, 18:18

Re: AutoHotkey v3.0-alpha.1 - Switching to JavaScript

Post by laozhhaiJohn » 31 Mar 2021, 17:17

:dance: 非常赞成发新版。人气确实有待提高。

User avatar
boiler
Posts: 16926
Joined: 21 Dec 2014, 02:44

Re: AutoHotkey v3.0-alpha.1 - Switching to JavaScript

Post by boiler » 31 Mar 2021, 17:24

But it’s not April 1st yet.

User avatar
joedf
Posts: 8953
Joined: 29 Sep 2013, 17:08
Location: Canada
Contact:

Re: AutoHotkey v3.0-alpha.1 - Switching to JavaScript

Post by joedf » 31 Mar 2021, 17:30

boiler wrote:
31 Mar 2021, 17:24
But it’s not April 1st yet.
Gasp! :o

waow.
Image Image Image Image Image
Windows 10 x64 Professional, Intel i5-8500, NVIDIA GTX 1060 6GB, 2x16GB Kingston FURY Beast - DDR4 3200 MHz | [About Me] | [About the AHK Foundation] | [Courses on AutoHotkey]
[ASPDM - StdLib Distribution] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library]


User avatar
SKAN
Posts: 1551
Joined: 29 Sep 2013, 16:58

OMG!

Post by SKAN » 31 Mar 2021, 18:46

Never saw this coming :|

gregster
Posts: 9002
Joined: 30 Sep 2013, 06:48

Re: AutoHotkey v3.0-alpha.1 - Switching to JavaScript

Post by gregster » 01 Apr 2021, 00:55

boiler wrote:
31 Mar 2021, 17:24
But it’s not April 1st yet.
In lexikos' timezone it was.

User avatar
boiler
Posts: 16926
Joined: 21 Dec 2014, 02:44

Re: AutoHotkey v3.0-alpha.1 - Switching to JavaScript

Post by boiler » 01 Apr 2021, 00:59

gregster wrote:
01 Apr 2021, 00:55
In lexikos' timezone it was.
I was thinking that might be the case, but I (mistakenly, apparently) thought he was in the US for some reason.

gregster
Posts: 9002
Joined: 30 Sep 2013, 06:48

Re: AutoHotkey v3.0-alpha.1 - Switching to JavaScript

Post by gregster » 01 Apr 2021, 01:05

boiler wrote:
01 Apr 2021, 00:59
gregster wrote:
01 Apr 2021, 00:55
In lexikos' timezone it was.
I was thinking that might be the case, but I (mistakenly, apparently) thought he was in the US for some reason.
Well, afaik, lexikos is from Australia.

User avatar
boiler
Posts: 16926
Joined: 21 Dec 2014, 02:44

Re: AutoHotkey v3.0-alpha.1 - Switching to JavaScript

Post by boiler » 01 Apr 2021, 01:11

I'm sure you're right. I had no basis.

User avatar
Nextron
Posts: 1391
Joined: 01 Oct 2013, 08:23
Location: Netherlands OS: Win10 AHK: Unicode x32

Re: AutoHotkey v3.0-alpha.1 - Switching to JavaScript

Post by Nextron » 01 Apr 2021, 02:09

That's elaborate. That woke me up quick! Here's me thinking that working from home would keep me safe from pranks. :facepalm:
lexikos wrote:
31 Mar 2021, 17:03
My interest in AutoHotkey development has dropped off repeatedly, and there have been times I've decided to officially retire from the community,
Considering the best lies contain some truth, this lingers even after considering the date. Then again, I'm still a content at v1.1.

User avatar
SKAN
Posts: 1551
Joined: 29 Sep 2013, 16:58

Re: AutoHotkey v3.0-alpha.1 - Switching to JavaScript

Post by SKAN » 01 Apr 2021, 02:46

Panda AV deleted 32bit .exe quoting unnamed virus. Had to restore it from quarantine.
Its fine online though.
https://www.virustotal.com/gui/file/d7c21e00c5727036460ccd837be93888c6c7b1c34c70b32d1254d154e571b433/detection

My first successful jk script :thumbup:

Code: Select all

msgBox("Hello World");

User avatar
Ragnar
Posts: 613
Joined: 30 Sep 2013, 15:25

Re: AutoHotkey v3.0-alpha.1 - Switching to JavaScript

Post by Ragnar » 01 Apr 2021, 03:12

Definitely an interesting project. Moreover, the provided examples seem to work. The only thing I'm unsure of is whether this is actually an elaborate April Fool's joke or not :HeHe:

OpalMonkey
Posts: 18
Joined: 23 Jan 2014, 03:02

Re: AutoHotkey v3.0-alpha.1 - Switching to JavaScript

Post by OpalMonkey » 01 Apr 2021, 04:24

Ragnar wrote:
01 Apr 2021, 03:12
The only thing I'm unsure of is whether this is actually an elaborate April Fool's joke or not :HeHe:
If it is a joke, it's so elaborate and deadpan. And if it's true, it seems like a sudden change of course. But the fact that it's functional and actually feels like it could make sense is really messing with me. It's got me split. Every time I think I'm sure it's one way or the other, a bit of doubt creeps in.

If it's a joke, it's the best I've seen in ages. And if it's not, it's a very interesting turn of events. You're great, lexikos, but this is messing with my head T_T

User avatar
joedf
Posts: 8953
Joined: 29 Sep 2013, 17:08
Location: Canada
Contact:

Re: AutoHotkey v3.0-alpha.1 - Switching to JavaScript

Post by joedf » 01 Apr 2021, 08:54

Well at first, looking the decompiled source... I thought there's some legitimacy? :?:

AutoHotkey(32|64).exe ahk script source
Image Image Image Image Image
Windows 10 x64 Professional, Intel i5-8500, NVIDIA GTX 1060 6GB, 2x16GB Kingston FURY Beast - DDR4 3200 MHz | [About Me] | [About the AHK Foundation] | [Courses on AutoHotkey]
[ASPDM - StdLib Distribution] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library]

gregster
Posts: 9002
Joined: 30 Sep 2013, 06:48

Re: AutoHotkey v3.0-alpha.1 - Switching to JavaScript

Post by gregster » 01 Apr 2021, 09:10

I like the jk file extension. ;)

It's not a question if it works, but if it is meant seriously, or to be taken literally... there, I have strong doubts :shh:
I think the date is no coincidence.

It seems like an impressive demo of the v2 capabilities, though.

User avatar
boiler
Posts: 16926
Joined: 21 Dec 2014, 02:44

Re: AutoHotkey v3.0-alpha.1 - Switching to JavaScript

Post by boiler » 01 Apr 2021, 09:20

Yes, .jk was the clincher for me. Nicely done, lexikos!

User avatar
Cerberus
Posts: 172
Joined: 12 Jan 2016, 15:46

Re: AutoHotkey v3.0-alpha.1 - Switching to JavaScript

Post by Cerberus » 01 Apr 2021, 18:02

This is the way forward. Good-bye, V2.

hasantr
Posts: 933
Joined: 05 Apr 2016, 14:18
Location: İstanbul

Re: AutoHotkey v3.0-alpha.1 - Switching to JavaScript

Post by hasantr » 01 Apr 2021, 21:45

I hope it's real. Now everything is on the web and maybe the AUTOHOTKEY with JS provides more control on the web. So I hope that.

swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: AutoHotkey v3.0-alpha.1 - Switching to JavaScript

Post by swagfag » 02 Apr 2021, 01:59

i might have to unironically switch to using this

Post Reply

Return to “Announcements”