4

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.

bbb
  • 1,479
  • 2
  • 15
  • 28
  • Simply use a trojan own your own system – Bgl86 Oct 01 '15 at 13:18
  • Could you explain what you mean by this? – bbb Oct 01 '15 at 13:25
  • 2
    Windows was not written in .NET so looking for .NET tooling isn't going to be helpful. You can see the low-level messaging with the Spy++ utility. Understanding the basics is pretty important to make sense of what you see, doubtful that this utility is included with the free VS edition you are probably using. Focus on learning C# programming first, hacking the operating system can wait. – Hans Passant Oct 01 '15 at 13:51

2 Answers2

1

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.

Vasily Ryabov
  • 9,386
  • 6
  • 25
  • 78
  • Thanks for your response! I'm planning on making a desktop application that will allow one user to record a sequence of keystrokes and mouse movements/clicks etc. using their own hardware and save this sequence as a file. I want another user to be able to replay this file on their own machine, resulting in the exact same sequence of events as recorded by the first user. Which of these options would allow me to also view a record of the events that have happened? – bbb Oct 02 '15 at 13:38
  • I know about `WH_JOURNALRECORD` and `WH_JOURNALPLAYBACK` hooks which able to record and replay all system events. See JournalRecordProc callback docs: https://msdn.microsoft.com/en-us/library/windows/desktop/ms644983.aspx – Vasily Ryabov Oct 05 '15 at 19:51
  • I'm not sure it's able to replay events under another user. – Vasily Ryabov Oct 05 '15 at 19:51
  • Do you have any other documentation on this? Or maybe a tutorial or an example? I think this is what I need but I don't understand the documentation enough to be able to successfully implement it into my program – bbb Oct 05 '15 at 20:07
  • This question may be helpful: http://stackoverflow.com/questions/1811383/setwindowshookex-in-c-sharp – Vasily Ryabov Oct 05 '15 at 20:15
  • One more useful experience: http://stackoverflow.com/questions/9317123/using-wh-journalrecord-and-cancel-does-seem-to-return-the-wm-canceljournal – Vasily Ryabov Oct 05 '15 at 20:20
  • There is also good article on CodeProject: http://www.codeproject.com/Articles/6362/Global-System-Hooks-in-NET – Vasily Ryabov Oct 05 '15 at 20:23
  • 1
    Regarding UI Automation, that API does not allow you to learn about keyboard or mouse activity. UI can raise UIA events that may occur as a result of keyboard or mouse activity, but the events do not give you any information about that keyboard or mouse activity. For example, if the user tabs to a button, the UI framework will usually raise a UIA FocusChanged event to let UIA clients know that keyboard focus has moved to the button. Or when a button is clicked, the UI framework will sometimes raise a UIA Invoked event. But these events don't tell you about the keyboard or mouse activity. – Guy Barker - Microsoft Oct 06 '15 at 01:25
  • Guy, is this comment in relation to the UI Automation API only? Is the program I intend to make still possible with the other methods that Vasily has posted? – bbb Oct 06 '15 at 10:16
0

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.

bparent
  • 11
  • 2