C
C#7mo ago
Pandetthe

WPF, "emulate" mouse click

Hi. I am working with WPF and I am adding Wintab API(tablet API). I want to "emulate" mouse click event on specific coordinates to avoid creating own buttons and other controls that will have this compatibility. Is there any option to call some kind of event or easily create own?
9 Replies
Pandetthe
Pandetthe7mo ago
And I don't wanna move cursor to this position
exokem
exokem7mo ago
Why do you need to emulate a mouse click
Pandetthe
Pandetthe7mo ago
I have a pen input from Wintab that is independent from mouse. I want to have possibility e.g. clicking a button with pen
exokem
exokem7mo ago
Is it a physical pen device? I don't know if there is a way to force WPF events, but if not and nothing else works you could use possibly harmony to force trigger an event at the desired location
Pandetthe
Pandetthe7mo ago
Yes it is psychical wacom tablet I will try to find some solution Or maybe somebody else have any idea
Jester
Jester7mo ago
i wrote some code here to turn my tablet into a mouse. tl;dr you could use sendinput to send mouse clicks or mouse_event. but you will have to dllimport one of these functions https://github.com/QubitTooLate/RawWacom/tree/main/src
GitHub
RawWacom/src at main · QubitTooLate/RawWacom
Small app to use a Wacom tablet as a mouse. Contribute to QubitTooLate/RawWacom development by creating an account on GitHub.
Jester
Jester7mo ago
$dllimport
MODiX
MODiX7mo ago
You can use the DllImportAttribute to call functions from C dlls in C#. In newer versions of C# use LibraryImportAttribute. Example:
using System;
using System.Runtime.InteropServices;

class Example
{
// Use DllImport to import the Win32 MessageBox function.
[DllImport("user32.dll", CharSet = CharSet.Unicode)]
public static extern int MessageBox(IntPtr hWnd, String text, String caption, uint type);

static void Main()
{
// Call the MessageBox function using platform invoke.
MessageBox(new IntPtr(0), "Hello World!", "Hello Dialog", 0);
}
}
using System;
using System.Runtime.InteropServices;

class Example
{
// Use DllImport to import the Win32 MessageBox function.
[DllImport("user32.dll", CharSet = CharSet.Unicode)]
public static extern int MessageBox(IntPtr hWnd, String text, String caption, uint type);

static void Main()
{
// Call the MessageBox function using platform invoke.
MessageBox(new IntPtr(0), "Hello World!", "Hello Dialog", 0);
}
}
Jester
Jester7mo ago
im assuming you want to do a mouse click on your desktop trough code. if you want it just in your wpf app id suggest pinvoking PostMessage instead and sending a WM_LBUTTONUP