Open hrkrx opened 6 years ago
@hrkrx Is there an example program on how to use it in .net core framework?
I really doubt on the idea of using it in .NET Core. Because I noticed some Win32 API calls in this project... I don't think Win32 APIs would work in Mac OS and Linux...
@zaafar basically i removed all Forms/WPF dependencies and fixed all errors by implementing a MessageLoop and the enums for the interaction codes (eg. some number => some KeyPress)
@ge-xin i actually have a prototype working on Linux which detects the OS and if on Windows uses the Win32 API calls and if not tries to open the special devices file in /dev/input... but it still is a prototype so it has issues like it only supports keyboard input for now
Hi @hrkrx , thank you for the reply. I tried using your fork of the library to hook into the global keyboard/mouse events but failed. Basically, I created a new .NET Core 2.1 Console Application project with following code in it. Let me know what I did wrong.
using FormsReplacementLib;
using Gma.System.MouseKeyHook;
using System;
using System.Threading;
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
Hook.GlobalEvents().MouseClick += Hook_MouseClick;
Console.WriteLine("Bye World!.");
-> Application.Run(new ApplicationContext());
}
private static void Hook_MouseClick(object sender, MouseEventArgs e)
{
Console.WriteLine($"{e.X}, {e.Y}");
}
}
EDIT: I am using windows10 x64.
EDIT2: Updated the code, now I need to understand how can I do Application.Run(new ApplicationContext()); in .NET Core?
@zaafar the code in my Fork is a bit older, i will update this in the next few days and then i'll add some example code here
Thanks! Looking forward to the example.
Excellent work. I hope you reach the goal of this work.
@hrkrx did you update already? i would also be interested in seeing the latest code.
@hrkrx has it been a few days yet? Going on 11 months... was curious about the .core implementation of this as well as the others.
@hrkrx Could you update your fork to provide to latest code for GlobalMouseKeyHook .NET Core compatibility?
I stumbled upon this project via the old code project (https://www.codeproject.com/Articles/7294/Processing-Global-Mouse-and-Keyboard-Hooks-in-C) and i made it work in .net core
Basically i made a very simple MessageLoop in a seperate Thread where the globalhook is called from.
The benefits in my opinion are that it removes
manyall of the required dependencies on Forms/WPF for the hooks to work.I didn't dive in this git deep yet, but if there is interest i could help to improve the library.
This could also make it easier to port it to Linux/Mac