javascript to ahk

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Nick Riviera
Posts: 38
Joined: 25 Aug 2021, 02:47

javascript to ahk

Post by Nick Riviera » 28 Apr 2022, 04:50

How to pass this function to ahk function?
Thanks

Code: Select all

var x = 10;
var y = 10;

alert(res(200,300)+" & "+ res(400,500));  // MsgBox

function res(cw,ch){
    var cw, ch;
    
    var rw1 = Math.floor(cw/x);
    var rw2 = Math.floor(ch/y);
    var rh1 = Math.floor(ch/x);
    var rh2 = Math.floor(cw/y);
    
    var resRw1 = rw1*rw2;
    var resRw2 = rh1*rh2;
    
var max = Math.max(resRw1,resRw2);
return max
    }
datavectors
Posts: 6
Joined: 25 Apr 2022, 05:56

Re: javascript to ahk

Post by datavectors » 28 Apr 2022, 05:41

Just a caveat.
I am on Ubuntu (Linux) and need to reinstall Windows 10 before I can start testing AutoHotKey scripting. I don't know how to import Javascript into AHK,

However, meanwhile I suggest that you install Actiona from here:

https://jmgr.net/

Action is based on Qt4 and runs cross platform. Javascript is its main language, but Python, Selenium etc can be added.

Then you can either use Actiona to supplement AHK scripting, or using the binary .. actexec .. you can run the script from AHK. That is, the Actiona GUI is not needed after the script is tested.

Your test javascript has been placed in a Code object and a MessageBox used instead of alert.

I can see AHK and Actiona working together. AHK can drive Actiona and vice versa as subprocesses.
Take the xml script below and change extension to .ascr before running
either as GUI or through actexec.

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<scriptfile>
    <settings program="actiona" version="3.10.1" scriptVersion="1.1.0" os="GNU/Linux"/>
    <actions>
        <action name="ActionCode" version="1.0.0"/>
        <action name="ActionMessageBox" version="1.0.0"/>
    </actions>
    <parameters/>
    <resources/>
    <script pauseBefore="0" pauseAfter="0">
        <action name="ActionCode">
            <exception id="0" action="0" line=""/>
            <exception id="1" action="0" line=""/>
            <exception id="2" action="1" line=""/>
            <parameter name="code">
                <subParameter name="value" code="1">var x = 10;
var y = 10;

// alert(res(200,300)+&quot; &amp; &quot;+ res(400,500));  // MsgBox

Console.print(res(200,300)+&quot; &amp; &quot;+ res(400,500));

var msg = (res(200,300)+&quot; &amp; &quot;+ res(400,500));

function res(cw,ch){
    var cw, ch;
    
    var rw1 = Math.floor(cw/x);
    var rw2 = Math.floor(ch/y);
    var rh1 = Math.floor(ch/x);
    var rh2 = Math.floor(cw/y);
    
    var resRw1 = rw1*rw2;
    var resRw2 = rh1*rh2;
    
var max = Math.max(resRw1,resRw2);
return max
    }</subParameter>
            </parameter>
        </action>
        <action name="ActionMessageBox">
            <exception id="0" action="0" line=""/>
            <exception id="1" action="0" line=""/>
            <exception id="2" action="1" line=""/>
            <parameter name="customIcon">
                <subParameter name="value" code="0"></subParameter>
            </parameter>
            <parameter name="icon">
                <subParameter name="value" code="0">none</subParameter>
            </parameter>
            <parameter name="ifNo">
                <subParameter name="action" code="0">do_nothing</subParameter>
                <subParameter name="line" code="0"></subParameter>
            </parameter>
            <parameter name="ifYes">
                <subParameter name="action" code="0">do_nothing</subParameter>
                <subParameter name="line" code="0"></subParameter>
            </parameter>
            <parameter name="message">
                <subParameter name="value" code="0">$msg</subParameter>
            </parameter>
            <parameter name="textMode">
                <subParameter name="value" code="0">automatic</subParameter>
            </parameter>
            <parameter name="title">
                <subParameter name="value" code="0">Result</subParameter>
            </parameter>
            <parameter name="type">
                <subParameter name="value" code="0">ok</subParameter>
            </parameter>
            <parameter name="windowIcon">
                <subParameter name="value" code="0"></subParameter>
            </parameter>
        </action>
    </script>
</scriptfile>
User avatar
mikeyww
Posts: 27366
Joined: 09 Sep 2014, 18:38

Re: javascript to ahk

Post by mikeyww » 28 Apr 2022, 05:42

Code: Select all

Global y := 10, x := 10
MsgBox, 64, Result, % res(200, 300) " & " res(400, 500)

res(cw, ch) {
 rw1 := Floor(cw / x)
 rw2 := Floor(ch / y)
 rh1 := Floor(ch / x)
 rh2 := Floor(cw / y)
 Return Max(rw1 * rw2, rh1 * rh2)
}
datavectors
Posts: 6
Joined: 25 Apr 2022, 05:56

Re: javascript to ahk

Post by datavectors » 28 Apr 2022, 06:15

As a newcomer to this forum I posted a reply, suggesting a complementary tool which accepts Javascript (Actionscript) directly. And I tested that it works in Ubuntu.
True it is not AHK native but being cross platform it should work with AHK nicely.
But the post was not accepted.
What are the forum rules for suggesting complementary approaches to AHK?
User avatar
boiler
Posts: 17387
Joined: 21 Dec 2014, 02:44

Re: javascript to ahk

Post by boiler » 28 Apr 2022, 06:53

It's not that your post wasn't accepted. It just wasn't approved yet. Posts by new members need to be approved by moderators to prevent spam and other unwanted posts. The moderators are volunteers, so we don't have 24-hour coverage, and it sometimes takes some time to get posts approved. Please be patient.
Nick Riviera
Posts: 38
Joined: 25 Aug 2021, 02:47

Re: javascript to ahk

Post by Nick Riviera » 28 Apr 2022, 07:00

Thank you!
mikeyww wrote:
28 Apr 2022, 05:42

Code: Select all

Global y := 10, x := 10
MsgBox, 64, Result, % res(200, 300) " & " res(400, 500)

res(cw, ch) {
 rw1 := Floor(cw / x)
 rw2 := Floor(ch / y)
 rh1 := Floor(ch / x)
 rh2 := Floor(cw / y)
 Return Max(rw1 * rw2, rh1 * rh2)
}
Post Reply

Return to “Ask for Help (v1)”