C
C#15mo ago
Reversal

❔ 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
Pobiega
Pobiega15mo ago
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 terminal
Reversal
ReversalOP15mo ago
Yeah, I don't want to use the term "keylogger" but it basically does kind of the same tbh. But for other purposes obviously
Pobiega
Pobiega15mo ago
You'll need to expand on those purposes 🙂
Reversal
ReversalOP15mo ago
need to perform a left click on another device when a key is pressed on the current device. (think I wrote that twice) tldr; When a key is pressed I need to perform a left click on the other device
Pobiega
Pobiega15mo ago
any reason why this has to be a global input listener, instead of just being a button or a local-window thing?
Reversal
ReversalOP15mo ago
Well...
Azrael
Azrael15mo ago
This feels oddly specific.
Pobiega
Pobiega15mo ago
I'm kinda having to drag details out of you, which makes me think you're probably up to no good to be honest.
Reversal
ReversalOP15mo ago
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
Azrael
Azrael15mo ago
Do they allow virtual clicks?
Pobiega
Pobiega15mo ago
yeah, be aware that when software sends clicks, its noticable to the program receiving the click, if they care about it
Reversal
ReversalOP15mo ago
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?
Azrael
Azrael15mo ago
You're emulating clicks. I don't think that it's allowed.
Pobiega
Pobiega15mo ago
They can. If they bother.
Reversal
ReversalOP15mo ago
Teamviewer / Google desktop is emulating as well, no?
Pobiega
Pobiega15mo ago
yes
Reversal
ReversalOP15mo ago
Then it's 100% allowed
Pobiega
Pobiega15mo ago
Thats a curious conclusion to jump to
Reversal
ReversalOP15mo ago
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
Pobiega
Pobiega15mo ago
Do they explicitly mention that emulated/virtual clicks are ok? just get a KVM switch then
Reversal
ReversalOP15mo ago
They care more about user clicks rather than emulated/virtual clicks Because it's allowed to map a joystick button to a left click
Pobiega
Pobiega15mo ago
ok
Reversal
ReversalOP15mo ago
Does this KVM switch allow me to type on both devices at the same time?
Pobiega
Pobiega15mo ago
its a physical device, you connect your keyboard/mouse to it and it broadcasts your inputs to several computers connected to it
Reversal
ReversalOP15mo ago
But when I press A do I see A in both devices
Pobiega
Pobiega15mo ago
yes
Azrael
Azrael15mo ago
That's not emulation. That's called remapping.
Reversal
ReversalOP15mo ago
Yeah but it does a virtual click after remapping right or emulated click whatever u call it
Pobiega
Pobiega15mo ago
Depends on how the software/hardware works if the joystick driver supports remapping in it, it wont count as virtual
Azrael
Azrael15mo ago
That depends.
Pobiega
Pobiega15mo ago
but if its a pure software thing, it probably will
Azrael
Azrael15mo ago
Like he said.
Reversal
ReversalOP15mo ago
Again, I don't think they care about emulated clicks
Pobiega
Pobiega15mo ago
Yeah it wasnt really the core issue here. The core issue is the ethical problem, not the technical one.
Reversal
ReversalOP15mo ago
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
SinFluxx
SinFluxx15mo ago
Why would you need to type on both at once?
Azrael
Azrael15mo ago
I mean, your only solution would be to emulate them (software wise). You can do other stuff hardware wise.
Reversal
ReversalOP15mo ago
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?
Pobiega
Pobiega15mo ago
hm?
Reversal
ReversalOP15mo ago
Think I was in there long time ago
Pobiega
Pobiega15mo ago
The only server I "own" is my secret development lair 🙂
Pobiega
Pobiega15mo ago
Pobiega
Pobiega15mo ago
its just me and a bunch of bots 🙂 Did you perhaps mean.. uh.. Code2Gether?
Reversal
ReversalOP15mo ago
I think that one, u were showing us stuff with reflections and stuff
Pobiega
Pobiega15mo ago
Ah, yep. That was never my server, I just liked contributing
Reversal
ReversalOP15mo ago
Ahh, got link?
Pobiega
Pobiega15mo ago
Could find it if ya want, but it's not very active these days And certainly no hour of code sessions, sadly
Reversal
ReversalOP15mo ago
If it doesnt take much of your time I would like to be part of that server again otherwise it's fine I guess
Pobiega
Pobiega15mo ago
Dm'd
Reversal
ReversalOP15mo ago
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
Reversal
ReversalOP15mo ago
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
Reversal
ReversalOP15mo ago
Alrighty, thx folks I think we're almost done 😄
Jimmacle
Jimmacle15mo ago
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)
Reversal
ReversalOP15mo ago
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
SinFluxx
SinFluxx15mo ago
I thought there was a windows setting to make the num keys do mouse inputs
Reversal
ReversalOP15mo ago
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
Azrael
Azrael15mo ago
TCP to ensure that it actually happens.
Reversal
ReversalOP15mo ago
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
Azrael
Azrael15mo ago
If you're going to be performing a lot of clicks I'd still recommend TCP.
Reversal
ReversalOP15mo ago
Yeah I tried both tcp and udp for some reason tcp feels slightly better Even tho udp should be more performant
Jimmacle
Jimmacle15mo ago
on your local network the difference should be imperceptible
Reversal
ReversalOP15mo ago
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....
Accord
Accord15mo ago
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.
Want results from more Discord servers?
Add your server