Low level keyboard hook - windows-7

I just bought a new keyboard, and I'm interested in tracking exactly how many keypresses/strokes I make during the entire life of the keyboard. (I would want to just record keyUp, as I don't care about repeats)
I've been googling around for the best way to do this, but I don't even know what approach to take, so I'm having trouble searching intelligently.
Also, the only language I've really worked with is C#. Haven't done anything with C/C++ or WinAPI
Is it difficult to modify the Win 7 drivers directly?
I do want to be able to record keystrokes from the moment the computer boots, but this may not be easily done.
I would prefer to use an existing driver or hook, as I really don't care to get into learning device drivers right now.
I've looked briefly at Ctrl2Cap, but I don't know how to modify something like that to suit my case.
Other questions I looked at,
Writing a keyboard device driver
Low level keyboard Hook not at UI thread
This one indicates writing a USB Filter driver may work, but I have no clue where to start on that.
Disabling the keyboard in windows c++?

It is not necessary to go the driver route, which is not for the faint of heart. You can use use a low level keyboard hook which will work fine from .NET.
I did a quick bing and found the following on codeplex
http://globalmousekeyhook.codeplex.com/
It should get you going

If you want to do that you need to use Kernel Level Keylogger. It's grabs the keystrokes before the operating system takes effects and this one 99% invisible for detection techniques. Then you can grab the Windows Log On screen typed things like password/username etc.
#ChrisTaylor's key logger not work for WinLog-on Screen I reckon. If you can install the keyboard driver filter before the system keyboard device driver take a action you can handle windows user login screen also. But In order to install this driver level key hook you need to have administrator privileges.
I found Unix and Windows Keyloggers from Github. Free to play with this https://www.adlice.com/kernelmode-rootkits-part-3-kernel-filters/ and have fun!

That, what you want is dangerous!
With the same code everyone can create keylogger*
But if you not a virus creator then I recommend you to search "hotkeying in C/C++" or something like that and hook keyboard with hotkeys!
I have written HotKey Maker in VB6 which can make hotkey from every button of keyboard.
But I really not interested in viruses :)
Good Luck !
*Virus which hooks your keyboard and send all what you wrote in keyboard to Virus owner

Related

Raw mouse and keyboard input for macOS games post-Catalina?

I have a feeling I know the answer to this question, but it's been surprisingly difficult to confirm it anywhere. Is it possible to get raw keyboard and mouse input post-Catalina without needing "Input Monitoring" access in the Security & Privacy preferences?
I've never programmed a game engine before on macOS, but so far as I can tell, the "usual" way for games to get raw mouse deltas and raw keyboard states has been to use IOKit's HID API. Up until recently, this apparently was also the only way to get input from Xbox and Playstation gamepads.
When I attempt to use the IOKit HID API to get mouse and keyboard input, I receive a prompt to allow Input Monitoring in Security & Privacy preferences. Elsewhere on the internet, I've learned that this is due to a change in macOS Catalina: to use IOKit HID input handling, you now need the Input Monitoring permission. As far as I'm concerned, it's a deal-breaker for my game to require users turn this on.
Am I understanding this situation correctly? And if I am, is it just not possible to get raw (unprocessed) keyboard and mouse input without the Input Monitoring permission? I mean, I can hack together a solution for FPS-style mouse input using mouseMoved: events and the like, but such a solution would disallow sub-pixel precision and would subject my game to macOS's cursor acceleration. Is there another solution that games/game engines use?
If you’re willing to take on the macOS 11 requirement, it seems like Apple added raw keyboard and mouse support to the Game Controller framework. Seems to even support caps lock.
https://developer.apple.com/documentation/gamecontroller/gckeyboardinput?language=objc

Can I control the state of the Speaker Icon with Delphi code

Is it possible to control (Enable/Disable) the Speaker Icon in Delphi Code.
Is there a registry entry for this?
Many Thanks...
While it might be possible to "hide" the icon by changing a undocumented registry value, the user can unhide it again in the tray icon options so this is not really a permanent solution.
If you insist on ignoring your users desire to mute their machine you can unmute the volume programmatically.
On Windows XP/2003 and older you will have to use the old mixer API. This API is not fun to deal with and you have to remember to unmute both the Wave and master volume lines. See this and this for inspiration.
Vista and later has a new COM based API that should be less painful to deal with. Create a instance of IMMDeviceEnumerator and enumerate the render endpoints (or use GetDefaultAudioEndpoint) and call IAudioEndpointVolume::SetMute on the device endpoint. This example should be pretty close, just translate it to Delphi. Volume can also be controlled per application so you might need to deal with that as well if your users are clever.
Larry Ostermans blog is also a great source for help and details about this new API.
Note: As a workaround for your unmuting, the user can simply set the volume really low to get rid of your sound. There is really no way for you to know if the sound is audible at a low volume level and setting it higher just because you can would be very evil and could really hurt somebody with headphones etc.

How to inject extra key presses into a keylogger?

I have a keylogger on my Win8 box. Nothing sinister: it performs some useful extra work. Actually it is so useful that I want to trigger some of its functions when I am afk. Naturally AutoIt and such does not work (I've checked): the logger is hooked to a low-level keyboard hook (I guess), and real keyboard hooks are not triggered by virtual keyboard events (I believe).
Basically I need a virtual keyboard with real-look-alike keypresses.
(Edit: I've deleted my own "idea" how to solve this, it was bad anyway, and I have more understanding now)
Trying SendInput and why it does not work.
People suggested to try SendInput. In short: it does not work, because I've managed to raise integrity level of my pythonw.exe only to High, but the "keylogger" runs on System level, and, as said in SendInput doc
Applications are permitted to inject input only into applications that
are at an equal or lesser integrity level.
I've found a very nice python SendInput implementation at Python simulate keydown, in comments.
To check "integrity level" of the process you can use ProcessExplorer, View / Select Columns, check "Integrity Level".
ProcessExplorer shows my pythonw.exe which I "Run as Admin" at the IL "High", but AcrossServer, AcrossService and a spawned conhost.exe all have the IL "System". (Yes, I am trying to inject keys into the very nice Bluetooth keyboard simulator Across).
Next possible steps.
Raising the integrity level of my app to System:
make it a windows service;
make it a device(less) driver;
anything easier? or
Lowing the integrity level of AcrossService to (at least) High:
is it possible? Edit: it is possible, Control Panel / Services, change logon account to myself. Unfortunately, Accross stops working when lowered.
Create a Python equivalent of Across Server on Windows.
Number 3 seem the most socially useful and seems easier than creating a specialized device driver :) But am I missing some simpler possibilities?

Detecting GUI state and generating user input programmatically in Windows Xp

I am looking for a lightweight solution that would allow me to detect which form/ dialog is open in an application, then emit some keystrokes / mouse moves and clicks. I do not have control over (nor the source-code for) the application.
I am familiar with MacroMaker, also testing products like SQA / Mercury offer similar functionality. The last time I had hands on exposure in this are is late 2004, I welcome any pointers to bring my knowledge up to date.
AutoIt is a scripting environment for Windows with a long history. It's quite easy to use and flexible to do things like detect the open window or dialog, change to another one, type something, etc. I would definitely recommend it.
In case anybody is curious, in the end I decided to use Microsoft UI Automation. Here is nice intro:
http://msdn.microsoft.com/en-us/magazine/cc163288.aspx

intercepting keystrokes in OSX

I'd like to be able to listen to keystrokes systemwide in OSX to implement an utility like AHK on windows (the shortcuts part of AHK anyway), recognizing not only simply combinations of keys, but even more complex things like sequences etc..
I need someone to point me... where to start? How to listen to keybard events system wide? Maybe there's something in the cocoa framework or that's not where to look for?
Quartz event taps. Look up CGEventTapCreate in the Xcode doc viewer to get started. Note that the user must check "Enable access for assistive devices" in the Universal Access preference panel before you'll be able to monitor keyboard events. (And even then you won't see keystrokes within password fields.)

Resources