❔ How to capture keys?
Weird question but I need to capture keys without writing into a terminal/console. I think I need to use a service but how do I know which key is pressed without writing it into a program/console/terminal whatever gui
63 Replies
Define "capture keys"? Would your program still be in focus, or is it more or less a key logger?
For a console app that still has focus, you can use
var keyInfo = Console.ReadKey(true);
to capture a keystroke without it being printed to the terminalYeah, I don't want to use the term "keylogger" but it basically does kind of the same tbh. But for other purposes obviously
You'll need to expand on those purposes 🙂
any reason why this has to be a global input listener, instead of just being a button or a local-window thing?
Well...
This feels oddly specific.
I'm kinda having to drag details out of you, which makes me think you're probably up to no good to be honest.
Besides that I want to know how it's possible.. I am going to use it for a game. The game does not allow autoclicker but manual clicks ofc .. or remapped keys that are pressed as a left click
Do they allow virtual clicks?
yeah, be aware that when software sends clicks, its noticable to the program receiving the click, if they care about it
I mean.. if you consider left clicking with teamviewer virtual I think yes?
Or even google chrome desktop thingy
Hmm? I don't think they can distinguish emulated with real clicks can they?
You're emulating clicks.
I don't think that it's allowed.
They can.
If they bother.
Teamviewer / Google desktop is emulating as well, no?
yes
Then it's 100% allowed
Thats a curious conclusion to jump to
I mean, I don't need all of this tbh if I can just plugin a keyboard that can type on 2 devices at the same time
Do they explicitly mention that emulated/virtual clicks are ok?
just get a KVM switch then
They care more about user clicks rather than emulated/virtual clicks
Because it's allowed to map a joystick button to a left click
ok
Does this KVM switch allow me to type on both devices at the same time?
its a physical device, you connect your keyboard/mouse to it
and it broadcasts your inputs to several computers connected to it
But when I press A do I see A in both devices
yes
That's not emulation.
That's called remapping.
Yeah but it does a virtual click after remapping right
or emulated click whatever u call it
Depends on how the software/hardware works
if the joystick driver supports remapping in it, it wont count as virtual
That depends.
but if its a pure software thing, it probably will
Like he said.
Again, I don't think they care about emulated clicks
Yeah it wasnt really the core issue here.
The core issue is the ethical problem, not the technical one.
Yea, I mean it's up to you guys to believe me on this one. It's ok if you don't want to help me further. It will take only a bit longer
Also looking on this KVM switch it doesnt look like you can type on both devices simultaniously
Why would you need to type on both at once?
I mean, your only solution would be to emulate them (software wise).
You can do other stuff hardware wise.
Alright, I guess I have to go down the rabbit hole
Wanted to avoid using this dllimports and wish there was a library but I guess we have to take this path
@Pobiega still got ur discord server?
hm?
Think I was in there long time ago
The only server I "own" is my secret development lair 🙂
its just me and a bunch of bots 🙂
Did you perhaps mean.. uh.. Code2Gether?
I think that one, u were showing us stuff with reflections and stuff
Ah, yep. That was never my server, I just liked contributing
Ahh, got link?
Could find it if ya want, but it's not very active these days
And certainly no hour of code sessions, sadly
If it doesnt take much of your time I would like to be part of that server again
otherwise it's fine I guess
Dm'd
This can't be true. I am pretty sure there must be a library instead of manually calling the dllimport
After all those years there must be a generally accepted package
ahh bless there is this: https://github.com/prasannavl/WinApi/tree/master
GitHub
GitHub - prasannavl/WinApi: A simple, direct, ultra-thin CLR librar...
A simple, direct, ultra-thin CLR library for high-performance Win32 Native Interop - GitHub - prasannavl/WinApi: A simple, direct, ultra-thin CLR library for high-performance Win32 Native Interop
Alrighty, thx folks I think we're almost done 😄
This sounds like input broadcasting which for the games I play at least isn't allowed
(controlling multiple instances of the game with a single action/keypress)
I'm not going to control multiple instances
It's close to done but all it's going to do is: send a left click when a key is pressed
I thought there was a windows setting to make the num keys do mouse inputs
There is BUT I am going to press a key from a different device
so the keyboard is not connected to the device where it sends the left click
Is it better to use tcp or udp to perform left clicks when a key is pressed
TCP to ensure that it actually happens.
I don't really care of it not performing a click but I do more care about the smoothness of a click so it does not really do 3-4 clicks at the same time
If you're going to be performing a lot of clicks I'd still recommend TCP.
Yeah I tried both tcp and udp for some reason tcp feels slightly better
Even tho udp should be more performant
on your local network the difference should be imperceptible
Clicks feel a bit clunky tbh
I feel like I need to track the time that is pressed between the buttons and then perform a click or smth 😒
This just doesnt feel right....
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.