Using autohotkey.dll with java. (ahkgetvar always returns 1)

Ask for help, how to use AHK_H, etc.
tugenzi
Posts: 1
Joined: 31 Jan 2020, 14:09

Using autohotkey.dll with java. (ahkgetvar always returns 1)

01 Feb 2020, 06:28

Hello
I'm not sure if this is right place to ask but anyway....

I'm studying how to use autohotkey.dll with java and I encountered a problem when trying to use ahkgetvar command. The command always seems to return value between 1-9.
Does anyone know what I'm doing wrong here? :roll:



Here is the java code

Code: Select all


public class DllController {
	autoHotKeyDll lib;
	
	
	public interface autoHotKeyDll extends Library {
		public void ahkExec(char[] s);
		public void ahktextdll(char[] s);
		public void AhkThread(String ScriptOrFile);
		public void addFile(char[] filepath,char[] runtype);
		public String ahkgetvar(char[] varname,char[] getpointer);
		public Integer ahkassign (char[] varname,char[] value); //returns integer -1=fail 0=success
		public void ahkdll (char[] filename);
		public void ahkFunction(char[] functionname);
		
	}

	public DllController() {
		autoHotKeyDll dll = (autoHotKeyDll) Native.loadLibrary("AutoHotkey", autoHotKeyDll.class);

				
		String fileLoc = System.getProperty("user.dir")+"\\test.ahk";
		
		dll.ahkdll(convert(fileLoc));
		Integer a = dll.ahkassign(convert("MyVar"), convert("111"));
		String data = dll.ahkgetvar(convert("MyVar"),convert("0")); 
		
		
		System.out.println("value= "+data); //This always returns 1-9

	}	


and this is what my .ahk looks like

Code: Select all

#Persistent
global MyVar
MyVar:="1234"

message()
{
   MsgBox %MyVar%
}

HotKeyIt
Posts: 2364
Joined: 29 Sep 2013, 18:35
Contact:

Re: Using autohotkey.dll with java. (ahkgetvar always returns 1)

01 Feb 2020, 09:01

As far as I understand it should be public char[] ahkgetvar
And then:
String data = new String(dll.ahkgetvar(convert("MyVar"),convert("0")));
esaro
Posts: 1
Joined: 24 Nov 2017, 10:30

Re: Using autohotkey.dll with java. (ahkgetvar always returns 1)

12 Nov 2022, 08:43

Hello boys.
Using the ahkFunction function as shown below, I have managed to get values from autohotkey to Java. However it does not work with the ahkgetvar function. Does anyone know how it works? Thanks!

Code: Select all

public class Test
{
    public interface autoHotKeyDll extends Library {
        public void ahkExec(WString code);
        public void ahkdll(WString s,WString o,WString p);
        public void addFile(WString s, int a);
        public void ahktextdll(WString s,WString o,WString p);
        public Pointer ahkFunction(WString f);
        public Pointer ahkgetvar(WString var, WString mode);
        public void ahkassign(WString var, WString value);
    }
    
    
    public static void main(String args[]) throws InterruptedException {
    	System.out.println("Loading dll");
        autoHotKeyDll lib = (autoHotKeyDll) Native.loadLibrary("AutoHotkey.dll", autoHotKeyDll.class);
        
        System.out.println("initialisation");
        lib.ahktextdll(new WString(""),new WString(""),new WString(""));
        Thread.sleep(100);
        lib.addFile(new WString(System.getProperty("user.dir") + "\\lib.ahk"), 1);
        Thread.sleep(1000);

        System.out.println("function call");
        System.out.println("return:" + Integer.parseInt(lib.ahkFunction(new WString("function")).getWideString(0))); //OK return
        Thread.sleep(1000);
        
        System.out.println("set value with ahkassign");
        lib.ahkassign(new WString("myVar"), new WString("XYZ"));
        lib.ahkExec(new WString("msgBox % myVar"));
        Thread.sleep(1000);
        
        System.out.println("get value with ahkgetvar");
        System.out.println("return:" + lib.ahkgetvar(new WString("myVar"), new WString("0")).getWideString(0)); //Error return with GetVarPointer = 0
        System.out.println("return:" + lib.ahkgetvar(new WString("myVar"), new WString("1")).getWideString(0)); //Error return with GetVarPointer = 1
        Thread.sleep(1000);
    }
}

Return to “Ask for Help”

Who is online

Users browsing this forum: No registered users and 59 guests