How to handle an external HID button click in C# - c#

I'm trying to integrate a third party hardware to one of my existing projects . Basically the hardware has two buttons with different color leds on each button.
I am able to open and close each led with the library/manual which is provided by the manufacturer without any problem. My problem is I can not handle its buttons click events from any kind of software C/C#/VB etc...
I mean when I press one of its buttons it acts like any input device and effects the cursors current position like a keyboard key or mouse click due the opened program(For example if Ms Word is opened currently it acts like space key?). The DLL or manual has no special function for this purpose (like a mouse click event?).
So what I'm asking is there any general way to handle any external device button click inside a C# program? How the currently running software suppose to understand a button is clicked and enter the desired method in the code?
Any clue or tip would be highly appreciated.
Thanks...

Related

Trying to detect and gather data on click outside application

I would like to know if it is possible to, while running a WPF window application in Visual Studio, wait for the user to click anywhere on the screen (not necessarily inside the window of my application - for the purpose of my application, the click would most likely occur inside a browser page) and then gather the information about the click (like inside the window of which application the user clicked, or the selector of the html element the user clicked)? I know this question might be very confunsing but this is basically my last resort since researching on the Internet hasn't helped me much. Just to provide a better idea of what I seek, it's like what the 'Extract Structured Data' Activity does in UiPath. Oh and I'm using C# by the way.
You can try and use this external library called GlobalMouseHook.
This library allows you to tap keyboard and mouse, detect and record their activity even when an application is inactive and runs in background.
Here is what you can do with this library:
Mouse coordinates
Mouse buttons clicked
Mouse drag actions
Mouse wheel scrolls
Key presses and releases
Special key states
Hope this helps.

change mouse button function

i've new mouse gaming that have several additional button. this mouse doesn't include application to allow user modifying function for the button. i like to change just like sharpkeys do. If there's any application that can allow me, can you tell me what is it? Or if there's no application yet, i im interested to starting developing.
for development choice, i've 2 option, develop with electron(javascript) or c#(the same programming language used by sharpkeys). can you recommend me which one is better?
update:
from this following link
https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/button
we can detect that every button has their own key code, my mouse button additional key code is 3 and 4. how can i modify these key become a same function like home/end in my computer keyboard?
You didn't state clearly about what you want to achieve.
Press a mouse button and act like "go to top of the page" ( what home key does ).
Press a mouse button and act like press home, and press home is defined by yourself.
I'll try to answer both.
According to your link, I found this
For solution 1.
You need mouse button act as "go to the top of page", you shall dig about how to "go to
the top of page".
For solution 2.
Keyboard event will tell you which key is pressed.
You may route mouse event and keyboard event to the same function.
i'm also found other application for alternatives for the solution to my problem, It's Mouse Manager. However, i'm still interested to develop application that can customize the mouse gaming button, for future development.

C#/.NET - View a list of system events ie. Windows that have been displayed, buttons that have been clicked etc

I'm completely new to C# and the .NET framework so forgive me if this is a silly question.
Is there any way of viewing a list of all of the events that have happened on a Windows system as a result of keystrokes and mouse movements etc.? So for example when I click on the Start menu, the Start menu is displayed or when I click the "Apply" button within a settings sub-menu, the settings are applied.
Is there any part of the .NET framework that will allow me to view all of these events/actions and record them via a C# program? Any help would me greatly appreciated! Thanks in advance.
UI Automation API is what you need. For listening automation events there are few kinds of handlers: AutomationEventHandler, StructureChangedEventHandler and 2 others.
There is another way for native windows: global mouse and keyboard hooks. See SetWindowsHookEx function.
C# in visual studio designer gives you the ability to respond to all kinds of events, like mouse moves and clicks. If you click on the object you want events from, then go to the events pane, you will see a list of all the events for that object. double click in the textbox next to it and it will auto-generate an event handler in your code. When the event is triggered, it will go to this method and do any code you provide there; IE log the action however you choose.

Right click, text capture

I have a c# application that runs in the bottom right corner of the page, i was wondering how i could go about making my application appear when the user selects some text anywhere (say a pdf, browser etc) and then right clicks, goes to my custome selection bit say and it pastes that text in to my running application.
If anyone made any sense of that could you advise me in to what i need to be researching to get it done.
Thanks
I've got this dictionary which does something similar.
Here's its mode of operation (or at least what I think it does)
When there is a double click, it sends a key command (probably Ctrl+C) to copy the selected text. It then reads the text from the clipboard.
For your purpose, you could implement the mouse listening and sending keystrokes with this article I found on CodeProject: InputManager library.
You then retrieve the copied text from the clipboard and do whatever you want with it.
Have a look at a Clipboard monitor
You can hook into the windows messaging api, probably there is a Text-selected event.

Prevent Window Focus Change

I'm trying to help a disabled person with a small bit of code to help him play a game easier. He is limited to a trackball and a single button.
Currently he uses the onscreen keyboard and has managed to play other games using it. I've created a small bit of code to try and make his live easier. It uses hover buttons for the keys. When the mouse pointer enters the button it sends key down, when it moves off the button it sends key up.
I have that working and I think (or hope) he's going to like it. It worked pretty well when I tested it.
I want to add one more piece of functionality to it. If he clicks while over my control, I want to send a different key stroke. Not a problem, I can do that. However, when I do that window focus shifts from the game to my control.
I found this on MSDN:
http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/48737c2b-7e6f-4ade-ac1c-7dd2f5cc2b88/
That works to prevent my window from activating, but it still causes the game to lose focus. I can set the focus back to the game, but I would prefer if it just never lost focus.
I'm coding in C# and WPF.
Anyone have any ideas on how you might do that?
John Fenton
Hook in some low level mouse and keyboard hooks, and your application won't need to steal focus and give it back.
Take a look at this pastie of a simple WPF app, which is heavily based off of an article by Stephen Toub.
Whenever you left click, anywhere, a second left click is sent, so you effectively double click. You could achieve your goal by hiding your app whenever the user clicks, so that your app never steals focus. Then detect the location of the click, and decide if one of your buttons would have been pressed, and act accordingly.
I realize I'm digging this out of the past, but hopefully someone will find this answer helpful. Cheers, and good for you for turning your programming to assist a fellow human!
You could try canceling the event PreviewLostKeyboardFocus as mention in this blog:
http://immortalratblog.blogspot.com/2008/03/canceling-keyboard-focus-change-in-wpf.html
Im guessing that focus is lost be simulating the key press?

Categories