✅ Global keypress Simulation?

hello, i have a project where i need to perform global mouse and key Presses, i cant seem to find a way, or Library that can do that, i need to read an array of strings, to perform the presses, and i need to be able to simulate holding down the key and mouse for an amount of time, do you know ways or Librarys to do that? i programm in VS and use windows forms c#. (something like this https://www.nuget.org/packages/H.InputSimulator#readme-tab (i cant get said extra functions to work here))
14 Replies
lycian
lycian11mo ago
this just ends up using win32 APIs for input https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-sendinput What exactly isn't working?
SendInput function (winuser.h) - Win32 apps
Synthesizes keystrokes, mouse motions, and button clicks.
RohesKätzchen
RohesKätzchenOP11mo ago
i cant find a way to convert a string into the right format to send the key, and i cant get the key to be held down to get something like "llllllllllllllllllllllll"
No description
RohesKätzchen
RohesKätzchenOP11mo ago
i need something like this to work or be abe to convert it to the right format
No description
lycian
lycian11mo ago
I don't know much about the library, but I would expect something like this to work
c#
new InputSimulator()
.Keyboard
.KeyDown(VirtualKeyCode.VK_A)
.Sleep(1000)
.KeyUp(VirtualKeyCode.VK_A)
c#
new InputSimulator()
.Keyboard
.KeyDown(VirtualKeyCode.VK_A)
.Sleep(1000)
.KeyUp(VirtualKeyCode.VK_A)
That said, if it doesn't work you may have to keep sending the entry at an interval.
RohesKätzchen
RohesKätzchenOP11mo ago
I think i could make this work with a timer, but i still need so be able to send the input in some way starting with a String, because otherwise i would need to write code for every key and i dont want to do that
RohesKätzchen
RohesKätzchenOP11mo ago
i think i found somethink that could work, i found the keyword enum and there is something calles enum.TryParse() but i cant figure out how to use it. (and im not even sure if it does what i want it to do)
No description
lycian
lycian10mo ago
You shouldn't need to parse them if you know the key at time of code
RohesKätzchen
RohesKätzchenOP10mo ago
i dont know the key, my overall goal is to write a program that records a macro and plays it, i have the record part but i cant find a dynamic way to replay the array of keys, i would need to write a function for every key, but i think there shoul be a more elegant way to solve this problem?
RohesKätzchen
RohesKätzchenOP10mo ago
this is an example of a recorded macro i know how to read the file and convert the line into the right line( for example: Pressed: L to "VK_L") but i dont know how to convert this into the WindowsInput.VirtualKeyCode or whatever the format is called?
No description
lycian
lycian10mo ago
GitHub
H.InputSimulator/src/libs/H.InputSimulator/KeyboardSimulator.cs at ...
Allows you to simulate global mouse and keyboard events. - HavenDV/H.InputSimulator
lycian
lycian10mo ago
If that doesn't work and you need more fine grained here is how they construct the input list https://github.com/HavenDV/H.InputSimulator/blob/master/src%2Flibs%2FH.InputSimulator%2FInputBuilder.cs
GitHub
H.InputSimulator/src/libs/H.InputSimulator/InputBuilder.cs at maste...
Allows you to simulate global mouse and keyboard events. - HavenDV/H.InputSimulator
RohesKätzchen
RohesKätzchenOP10mo ago
thanks, this might be what i need, im going to test some things with it.
RohesKätzchen
RohesKätzchenOP10mo ago
i've figured out how to get from string to virtualkeycode format wich turn out to be a enumeration, and ive learned what enumerations are. this was the solution to my problem
No description
RohesKätzchen
RohesKätzchenOP10mo ago
now i need to figure out how to get the key to be held down, bc i think if i simulated the held down keypress by using timers and repeating the input it wouldnt be the same as actually the held down key
Want results from more Discord servers?
Add your server