Keysharp - C# port of AHK

Talk about things KeySharp, some related to AutoHotkey or C#
User avatar
mfeemster
Posts: 104
Joined: 24 Apr 2020, 18:30

Keysharp - C# port of AHK

23 Jan 2024, 15:33

Current version: 0.0.0.7

An Msi for the installer and a Zip for the portable can be found here:

https://bitbucket.org/mfeemster/keysharp/downloads/

Please read through the instructions, caveats and differences between Keysharp and AHK v2 here:

https://bitbucket.org/mfeemster/keysharp/src/master/

Running the program requires .NET 8 and Windows.

The Msi will register the .ks file extension so you can double click them to run after the installer completes.

It is recommended you use the included Keyview program to write your scripts to make sure they compile.

Sample scripts can be found within this thread.

We welcome feedback.
Last edited by mfeemster on 15 Feb 2024, 10:07, edited 4 times in total.
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Keysharp - C# port of AHK

26 Jan 2024, 01:09

Thx for the update :thumbup:
SOTE
Posts: 1426
Joined: 15 Jun 2015, 06:21

Re: Keysharp - C# port of AHK

08 Feb 2024, 21:13

Keep up the good work :salute:
burque505
Posts: 1736
Joined: 22 Jan 2017, 19:37

Re: Keysharp - C# port of AHK

09 Feb 2024, 08:10

This and a few other scripts were previously posted here.

FindFileString.ks

Code: Select all

; =============================================================================================================================================================
; Author ........: jNizM
; Released ......: 2021-04-23
; Modified ......: 2023-01-12
; Tested with....: AutoHotkey v2.0.2 (x64)
; Tested on .....: Windows 11 - 22H2 (x64)
; Function ......: FileFindString( FileName, Search )
; Keysharp ver...: 2024-01-24
; Parameter(s)...: FileName - path to the file
;                  Search   - the word or string to search for
;
; Return ........: Finds a specific word / string in a text file.
; =============================================================================================================================================================

#Requires AutoHotkey v2.0


FileFindString(FileName, Search)
{
	try
		File := FileOpen(FileName, "r-d")
	catch as Err
	{
		MsgBox "Can't open '" FileName "`n`n" Type(Err) ": " Err.Message
		return
	}

	Found := Map()
	while !(File.AtEOF)
	{
		if (InStr(GetLine := File.ReadLine(), Search))
		{
			Found[A_Index] := GetLine
		}
	}
	File.Close()

	return Found
}


; =============================================================================================================================================================
; Example
; =============================================================================================================================================================

for Index, Value in FileFindString("YourFileWithFullPath.txt", "YourString") ; ADAPT THIS LINE FOR YOUR OWN USE
	MsgBox "Line: " Index "`n`n" Value
Last edited by burque505 on 09 Feb 2024, 08:19, edited 1 time in total.
burque505
Posts: 1736
Joined: 22 Jan 2017, 19:37

Re: Keysharp - C# port of AHK

09 Feb 2024, 08:11

FileCountLines.ks

Code: Select all

; =============================================================================================================================================================
; Author ........: jNizM
; Released ......: 2021-04-23
; Modified ......: 2023-01-12
; Ported to KS...: 2024-01-23
; Tested with....: AutoHotkey v2.0.2 (x64)
; KS Test with...: Keysharp v0.0.0.6
; Tested on .....: Windows 11 - 22H2 (x64)
; Function ......: FileCountLines( FileName )
;
; Parameter(s)...: FileName - path to the file
;
; Return ........: Count the number of lines in a file.
; =============================================================================================================================================================

#Requires AutoHotkey v2.0


FileCountLines(FileName)
{
	try
		File := FileOpen(FileName, "r-d")
	catch as Err
	{
		MsgBox "Can't open '" FileName "`n`n" Type(Err) ": " Err.Message
		return
	}

	CountLines := 0
	while !(File.AtEOF)
	{
		File.ReadLine()
		CountLines++
	}
	File.Close()

	return CountLines
}


; =============================================================================================================================================================
; Example
; =============================================================================================================================================================

MsgBox FileCountLines("YourFileHere.txt")
burque505
Posts: 1736
Joined: 22 Jan 2017, 19:37

Re: Keysharp - C# port of AHK

09 Feb 2024, 08:12

DisableCloseButton.ks

Code: Select all

; PORTING REQUIRED (MINOR)
; =============================================================================================================================================================
; Author ........: jNizM
; Released ......: 2017-04-13
; Modified ......: 2023-01-16
; Tested with....: AutoHotkey v2.0.2 (x64)
; Tested on .....: Windows 11 - 22H2 (x64)
; Function ......: GuiDisableCloseButton()
; KS ............: 2024-01-23
; Parameter(s)...: Handle - Gui.Hwnd
;
; Return ........: Disables the GUI Close Button.
; =============================================================================================================================================================

#Requires AutoHotkey v2.0


Main := Gui()
Main.OnEvent("Close", (*) => ExitApp())
Main.Show("w400 h300")
GuiDisableCloseButton(Main.Hwnd)


GuiDisableCloseButton(Handle)
{
    static SC_CLOSE    := 0xF060
    static MF_GRAYED   := 0x00000001
    static MF_DISABLED := 0x00000002

    hMenu := DllCall("user32\GetSystemMenu", "Ptr", Handle, "Int", False, "Ptr")
    DllCall("user32\EnableMenuItem", "Ptr", hMenu, "UInt", SC_CLOSE, "UInt", MF_GRAYED | MF_DISABLED)
    return DllCall("user32\DrawMenuBar", "Ptr", Handle)
}


; =============================================================================================================================================================
burque505
Posts: 1736
Joined: 22 Jan 2017, 19:37

Re: Keysharp - C# port of AHK

09 Feb 2024, 08:14

DisableMove.ks

Code: Select all

; PORTING WAS REQUIRED (MINOR)
; =============================================================================================================================================================
; Author ........: jNizM
; Released ......: 2017-04-13
; Modified ......: 2023-01-16
; Tested with....: AutoHotkey v2.0.2 (x64)
; Tested on .....: Windows 11 - 22H2 (x64)
; Function ......: GuiDisableMove()
; Tested with KS.: 2024-01-23
; Parameter(s)...: Handle - Gui.Hwnd
;
; Return ........: Disables the GUI Move function.
; =============================================================================================================================================================

#Requires AutoHotkey v2.0


Main := Gui()
Main.OnEvent("Close", (*) => ExitApp()) ; parens added for ExitApp
Main.Show("w400 h300")
GuiDisableMove(Main.Hwnd)


GuiDisableMove(Handle)
{
    static SC_MOVE      := 0xF010
    static MF_BYCOMMAND := 0x00000000

    hMenu := DllCall("user32\GetSystemMenu", "Ptr", Handle, "Int", False, "Ptr")
    DllCall("user32\RemoveMenu", "Ptr", hMenu, "UInt", SC_MOVE, "UInt", MF_BYCOMMAND)
    return DllCall("user32\DrawMenuBar", "Ptr", Handle)
}


; =============================================================================================================================================================
burque505
Posts: 1736
Joined: 22 Jan 2017, 19:37

Re: Keysharp - C# port of AHK

09 Feb 2024, 08:15

DNSServerList.ks

Code: Select all

; =============================================================================================================================================================
; Author ........: jNizM
; Released ......: 2023-01-17
; Modified ......: 2023-01-17
; Tested with....: AutoHotkey v2.0.2 (x64)
; Tested on .....: Windows 11 - 22H2 (x64)
; Function ......: DnsServerList()
; Keysharp ......: Tested with rebuilt Keysharp 2024-01-28
; Parameter(s)...: No parameters used
;
; Return ........: Gets a list of DNS servers for the local computer.
; =============================================================================================================================================================

#Requires AutoHotkey v2.0


DnsServerList()
{
    static STATUS_SUCCESS         := 0
    static DnsConfigDnsServerList := 6

    DllCall("dnsapi\DnsQueryConfig", "Int", DnsConfigDnsServerList, "UInt", 0, "Ptr", 0, "Ptr", 0, "Ptr", 0, "UInt*", &Size := 0)
    Buf := Buffer(Size)
    DNS_STATUS := DllCall("dnsapi\DnsQueryConfig", "Int", DnsConfigDnsServerList, "UInt", 0, "Ptr", 0, "Ptr", 0, "Ptr", Buf, "UInt*", Buf.Size)

    if (DNS_STATUS = STATUS_SUCCESS)
    {
        DNS_SERVER := Array()
        loop NumGet(Buf, 0, "UInt")
        {
            DNS_SERVER.Push(DllCall("ws2_32\inet_ntoa", "UInt", NumGet(Buf, 4 * A_Index, "UInt"), "AStr"))
        }
        return DNS_SERVER
    }

    throw OSError()
}


; =============================================================================================================================================================
; Example
; =============================================================================================================================================================

DNS := DnsServerList()
loop DNS.Length
    MsgBox DNS[A_Index]
burque505
Posts: 1736
Joined: 22 Jan 2017, 19:37

Re: Keysharp - C# port of AHK

09 Feb 2024, 08:15

CreateUUID.ks

Code: Select all

; =============================================================================================================================================================
; Author ........: jNizM
; Released ......: 2021-10-13
; Modified ......: 2023-01-12
; Tested with....: AutoHotkey v2.0.2 (x64)
; Tested on .....: Windows 11 - 22H2 (x64)
; Function ......: CreateUUID()
; Keysharp ......: Tested with rebuilt Keysharp 2024-01-28
; Parameter(s)...: No parameters used
;
; Return ........: Creates an Universally Unique IDentifier (UUID).
;                  A UUID provides a unique designation of an object such as an interface, a manager entry-point vector, or a client object.
; =============================================================================================================================================================

#Requires AutoHotkey v2.0


CreateUUID()
{
	static RPC_S_OK := 0, UUID := ""

	pUUID := Buffer(16)
	if (DllCall("rpcrt4\UuidCreate", "Ptr", pUUID) = RPC_S_OK)
	{
		if (DllCall("rpcrt4\UuidToStringW", "Ptr", pUUID, "Ptr*", &StringUuid := 0) = RPC_S_OK)
		{
			UUID := StrGet(StringUuid)
			DllCall("rpcrt4\RpcStringFreeW", "Ptr*", StringUuid)
		}
	}
	return UUID
}


; =============================================================================================================================================================
; Example
; =============================================================================================================================================================

MsgBox CreateUUID()
burque505
Posts: 1736
Joined: 22 Jan 2017, 19:37

Re: Keysharp - C# port of AHK

09 Feb 2024, 08:16

@SKAN's script to show/hide desktop icons, ported to Keysharp.

Code: Select all

; Thanks to SKAN for this and his many other scripts!

^#!i::
{
    DesktopIcons()
}

DesktopIcons(Show:=-1, hWnd:=0) {                    ; By SKAN on D35D @ tiny.cc/desktopicons
If ! hWnd := DllCall("GetWindow", "Ptr",WinExist("ahk_class Progman"), "UInt",5, "Ptr")
     hWnd := DllCall("GetWindow", "Ptr",WinExist("ahk_class WorkerW"), "UInt",5, "Ptr")
If DllCall("IsWindowVisible", "Ptr",DllCall("GetWindow","Ptr",hWnd, "UInt",5, "Ptr")) != Show
   DllCall("SendMessage","Ptr",hWnd, "Ptr",0x111, "Ptr",0x7402, "Ptr",0)
}
burque505
Posts: 1736
Joined: 22 Jan 2017, 19:37

Re: Keysharp - C# port of AHK

09 Feb 2024, 08:18

@iseahound's Capslock-to-modifier script from here , ported to Keysharp. Very minor mod required.

Code: Select all

; Modded for Keysharp 2024-01-30 by burque505
; Original script by iseahound
; is here: https://www.autohotkey.com/boards/viewtopic.php?f=96&p=556135#p556135

CapsLock:: {
    start := A_TickCount                              ; run once
    KeyWait('CapsLock')                               ; wait for Capslock to be released
    if (A_TickCount - start < 200)                    ; in 0.2 seconds
    and KeyWait('CapsLock', 'D T0.2')                 ; and pressed again within 0.2 seconds
    and (A_PriorKey = 'CapsLock')                     ; block other keys
       SetCapsLockState(!GetKeyState('CapsLock', 'T')) ; Only this line was modded for Keysharp
 }
 *CapsLock:: return                                   ; This forces capslock into a modifying key.
 
 #HotIf GetKeyState("CapsLock", "P")
 q:: MsgBox "You pressed CapsLock + q"
 ^w:: MsgBox "You pressed CapsLock + Control + w"
 #HotIf

 !Esc::ExitApp()
User avatar
mfeemster
Posts: 104
Joined: 24 Apr 2020, 18:30

Re: Keysharp - C# port of AHK

15 Feb 2024, 10:05

New release 0.0.0.7

This fixes various parsing bugs as well as some issues with DllCall().
eugenesv
Posts: 175
Joined: 21 Dec 2015, 10:11

Re: Keysharp - C# port of AHK

03 Mar 2024, 10:52

Very interesting project! Would you please add the key benefits to its Readme/description? I've followed the other thread and read the repo, but still not very clear.

One obvious awesome benefit was cross-platform functionality, but then I saw that Wayland would unlikey be supported, so then this benefit is unlikely to materialize

Then the scripts are compiled before being run - is this supposed to improve scripts performance? And if yes, in which areas?

Another is real threads, though there is a multithreaded AHK variant (and haven't seen many examples of scripts using that, so now sure where that would help)

Thanks!
User avatar
mfeemster
Posts: 104
Joined: 24 Apr 2020, 18:30

Re: Keysharp - C# port of AHK

04 Mar 2024, 10:06

Thanks for trying it out.

The intended benefits are that we can eventually make it cross platform. I aim to get there someday, but it will be a large undertaking. As you noticed, it'll only be doable on systems using X11.

The performance is hit or miss. I've tested a few things where AHK is faster, so it just depends.

So for now, the benefit is that it's just a different way of doing things and I hope people try it out.
user7500

Re: Keysharp - C# port of AHK

10 Mar 2024, 14:54

First of all gratz for the project!

I've read all the thread and would like to point out a pair of passages.

I clearly understand that supporting Wayland require an extra effort however let me tell this, isn't this part crucial for the sake of the project itself? Aside the .NET / Mono port can't a Windows user just use one of the already existing windows builds of AHK? I think the best goal of this project would be make the ahk script being able to load steady on both x11 and wayland (basically full Ubuntu support)

I see that you are using bitbucket, don't know what are the reasons behind that but can't the project be moved on github and add more developers? maybe 2-3 ones that could volounteer to make the wayland part fully functioning and reducing the big load you have on your shoulder as one man army developer.

The work you did until now is awesome but could you consider calling for more help and extending the support? consider maybe getting also donations ore use crowfunding in case.

Thanks, hoping in full linux support asap
Best regards.
User avatar
mfeemster
Posts: 104
Joined: 24 Apr 2020, 18:30

Re: Keysharp - C# port of AHK

10 Mar 2024, 23:50

Thanks for your interest, I appreciate it.

You are correct, that the main strength will be cross platform support. On Windows, it's not really adding much new functionality, but instead is just a different way of doing things.

However, getting it working on x11 and Wayland will be a monumental effort.

As I mentioned earlier, I am taking a few months off the project to catch up on other things.

I have one person helping me test, and additional developer support would indeed be welcome. However, the limiting factor is not money or what website it's hosted on. Instead, it's the massive time commitment involved which will likely span years. It was 3.5 years to do Keysharp, on top of 5 years on and off for IronAHK.

When I get back on the project later this year, you're welcome to contribute code. I am also in the Discord in the #keysharp channel under the Community Projects section.
Guest

Re: Keysharp - C# port of AHK

11 Mar 2024, 05:59

However, getting it working on x11 and Wayland will be a monumental effort.
I see and understand your concerns but probably there's an approach that can be used with less pain and stress.
When I get back on the project later this year, you're welcome to contribute code.
I was a developer then moved on project handling, even if I would have all the time and the skills required probably only my hands would not be very useful, but I will try to help in another way let me explain below.
I have one person helping me test, and additional developer support would indeed be welcome. However, the limiting factor is not money or what website it's hosted on. Instead, it's the massive time commitment involved which will likely span years. It was 3.5 years to do Keysharp, on top of 5 years on and off for IronAHK.
These are major pain points, effort and time required. Many of the greatest and best software of the humanity shared the same problems think of the monumental effort on Linux Kernel, or debian distribution or softwares like blender. At a certain point all of this great projects started restructuring themself in another way.

You have the big merit of taking the heritage of the IronAHK and refunding with your very committed time the project.

Why don't consider the opportunity to move from developer to project leader?

You spent lot of time on all the code of Keysharp, who if not you have the knowledge of all the details of the ongoing project, knows what to do and can mentor the new developers on what piece of code still have to be written ?

I suggested before github because is de facto standard among developers even more young and unexperienced ones to access and contribute other persons code. I guess that you choose bitbucket because you are more experienced and you value it better. Github on the other hand is more friendly for junior developers and persons who are willing to help.

Making a public call for help in newsgroups, forums and
putting on a website can help. Indeed for the precious time you spent on the project until now, give it a monetary value because it's fair to do so a certain point. Wouldn't accepting donations or putting on a foundation to get fundrising and get supported be right?

Consider that all big companies also donate to open source world because themself use these softwares and there's a nice need of stable and functional ahk like sw in ubuntu/debian/suse world.

It could seems difficult but if you have some friends in lawyer and taxes they could help setup it easily.

That said all I can do until now is inspire you! With this route a monumental effort of years could be shrinked down in a finite number of months.

I wish you a great day and good luck for the project.
eugenesv
Posts: 175
Joined: 21 Dec 2015, 10:11

Re: Keysharp - C# port of AHK

12 Mar 2024, 12:46

I've noticed that your parser doesn't accept unicode in function/var names unlike AutoHotkey, so can't transition my beautifully named :) vars like move← := ...
User avatar
mfeemster
Posts: 104
Joined: 24 Apr 2020, 18:30

Re: Keysharp - C# port of AHK

13 Mar 2024, 08:53

eugenesv wrote: I've noticed that your parser doesn't accept unicode in function/var names unlike AutoHotkey, so can't transition my beautifully named :) vars like move← := ...
Thanks @eugenesv , good catch. I've made a ticket here: https://bitbucket.org/mfeemster/keysharp/issues/102/cant-accept-unicode-characters-in-function and will work on it when I get back on the project in a few months.

Return to “KeySharp”

Who is online

Users browsing this forum: No registered users and 32 guests