Question, need a utility to map or transform the key stoke, say when you press F6, replace the contents with a Mailing address, and Press F7 for the zip code of your city.
Answer, In C#, it’s easy and not easy. you have to wrap several Native APIs to hook the mapping point into the system, Easy one is it has one Great methods called Sendkeys.Send.
So eventually, we need one file to keep the mapping logic , here I just pickup the .config file, then the code. Code is here,you may just copy and save it as .cs file, then compile it.
using System; public class KeyMapper private static LowLevelKeyboardProc _proc = HookCallback; mappings = System.Configuration.ConfigurationManager.AppSettings; _hookID = SetHook(_proc); private static IntPtr SetHook(LowLevelKeyboardProc proc) private delegate IntPtr LowLevelKeyboardProc( private static IntPtr HookCallback( if (mappings[key] != null)
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)] [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)] [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)] |
Then we you started the console application.
wherever you enter F6, it will put a sample address there.
If you can’t compile the code , leave a comment , I will email you the compiled bits.
No comments:
Post a Comment