Hello everyone, I would like to write an application that would allow me to change the functions of the usually-useless F keys (especially F8, I hate that one) into functions that I specify in code. I would like to let some of them open certain files, or paste text.. etc

So how can I modify and disable key functions in C# without using hooks?

Recommended Answers

All 5 Replies

To clarify, are you wanting to change these keys for the system, or just within/for your running application?

To clarify, are you wanting to change these keys for the system, or just within/for your running application?

As long as the application is running, however the change would be universal across the system.
For example I'd change the F5 key to something other than refresh, so even if I go to Firefox or the desktop and press F5, the system would perform my function, not refresh.

Ideally, I'd save my changes as settings; and whenever I run my app, it would apply the modifications indicated by the settings and keep them until the application terminates.

So yeah, as long as the app is running.

I don't think you should be remapping keys across the entire system, unless you are creating a key mapping program that the user is in complete control over, including the ability to restore all previous/normal key mappings.

Using the RegisterHotKey function won't work for you because it fails if the mapping is already defined.

There is no easy way to do this that I am aware of. In theory, you could subclass the OS message loop to capture these keys and then redirect the message (using SendMessage ) as some other function.

I know you indicated "without using hooks", but if you are still interested in doing this, here are some basic links and further discussion:

Basic discussion of .NET Subclassing and OS Message Queue...

Subclassing Forms and Controls...

Simple hook installation with windows handle...

Keyboard hook example using WM_HOTKEY

Yeah, it seems using hooks is a more viable solution, I'm afraid.
Thanks for the link, I'll have a look at them.

Yeah, it seems using hooks is a more viable solution, I'm afraid.
Thanks for the link, I'll have a look at them.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.