VB.net with autohotkey.dll - functions?

Discuss other programming languages besides AutoHotkey
KoHx3
Posts: 13
Joined: 08 Jan 2017, 09:13

VB.net with autohotkey.dll - functions?

08 Jan 2017, 09:39

Hey there,
I want to make some stuff with VB.net and use some ahk scripts.
Actually I just need help to get the functions out of the .dll - and maybe a small example for it.
The Problem is - I dont want to register the autohotkey.dll file.
(Keyword: Export functions)

I found it over here (the way to import functions): https://autohotkey.com/board/topic/1082 ... verwenden/
(German thread)

I'm using the ahk.dll from Win32w. (From this one https://github.com/HotKeyIt/ahkdll-v1-release because I dont know - this were the one I got redirected to :lol: )
As I see now - there is a v2 version - maybe I should use this, depends on what you say.
Back to topic.

To call the DLL and import the function (ahktextdll were the example) I want to use, I've to use this code:

Code: Select all

Module Module1
    <DllImport("AutoHotkey.dll", CallingConvention:=CallingConvention.Cdecl, CharSet:=CharSet.Unicode)>
    Function ahktextdll(ByVal script As String, ByVal options As String, ByVal param As String) As Integer
    End Function
End Module
But which functions are out there? How I'm able to get them? Is there any list?
I definetly need something to reset the ahk script, add a script to the existing/running script, - something like this.

Hope you can help me out :)
Cheers
KoHx3
Posts: 13
Joined: 08 Jan 2017, 09:13

Re: VB.net with autohotkey.dll - functions?

11 Jan 2017, 10:26

Thanks for this advice but I'm not that taff to get the sense - nah - to get the functions out of it.
I'm also to stupid to use it correctly if I register the .dll of v1.

I want to combine scripts if the Checkbox is checked or not - but only ask for the Checked state if a button got clicked.
(Yea I do that with Strings at this point cause in my usual code I need them later)

Code: Select all

Public Class Form2
    Sub Test1()
        Dim ahk As Object
        ahk = CreateObject("AutoHotkey.Script")
        Dim n = vbLf

        ahk.ahktextdll("z::" & n &
        "Send {a}" & n &
        "Sleep 100" & n &
        "Send {b}" & n &
        "Sleep 100" & n &
        "Send {c}" & n &
        "Return" & n &
        "#If" & n &
        "Return")
    End Sub
    
        Sub Test2()
        Dim ahk As Object
        ahk = CreateObject("AutoHotkey.Script")
        Dim n = vbLf

        ahk.ahktextdll("x::" & n &
        "Send {d}" & n &
        "Sleep 100" & n &
        "Send {e}" & n &
        "Sleep 100" & n &
        "Send {f}" & n &
        "Return" & n &
        "#If" & n &
        "Return")
    End Sub
    
    Dim vTest1 As String = "0"
    Dim vTest2 As String = "0"
    
    Private Sub Checkbox1_CheckedChanged(sender As Object, e As EventArgs) Handles Checkbox1.CheckedChanged
        If Checkbox1.Checked = "True" Then
            vTest1 = "1"
        Else
            vTest1 = "0"
        End If
    End Sub
    
    Private Sub Checkbox2_CheckedChanged(sender As Object, e As EventArgs) Handles Checkbox2.CheckedChanged
    'It should clear/terminate all scripts over here and than it should add & run the script of Test1 or/and Test2 if it set to True / 1
    
        If Checkbox2.Checked = "True" Then
            vTest2 = "1"
        Else
            vTest2 = "0"
        End If
    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    If vTest1 = "1" Then
            'add the script (working)
            Test1()
       Else
            'at this point it should remove the script (how to?)
     End If
     
     If vTest2 = "1" Then
            'add the script (working)
            Test2()
       Else
            'at this point it should remove the script (how to?)
     End If
    End Sub
End Class
KoHx3
Posts: 13
Joined: 08 Jan 2017, 09:13

Re: VB.net with autohotkey.dll - functions?

18 Jan 2017, 18:41

Hey there - I still have the Problem that I cant use the addscript command.
I'm using the v1 .dll (registered).

The following code wont work (Also tried as Module and other Sub- but nothing worked and I need help.

Code: Select all

    Private Sub ButtonApply_Click(sender As Object, e As EventArgs) Handles ButtonApply.Click
        Dim ahk As Object
        ahk = CreateObject("AutoHotkey.Script")
        Dim n = vbCrLf
        'ahk.ahkTerminate()

        ahk.addscript("TestScript:" & n &
        "$r::" & n &
        "Send {x}" & n &
        "Send {y}" & n &
        "Return" & n &
        "#If" & n &
        "Return")

        If vScript1 = "1" Then
            ahk.ahkLabel("TestScript")
        End If

    End Sub
Any help? The only thing I can get to work is ahktextdll and ahkdll but I need to activate / deactivate the script If the checkbox is checked or not or something like this. D:
And this also should work on a computer without AHK installed. :/

Return to “Other Programming Languages”

Who is online

Users browsing this forum: No registered users and 1 guest