If your Methods is capsulated to ArcMap Command, you could use AcceleratorTable.
IAcceleratorTable pAccTable = m_app.Document.Accelerators;
UID uid = new UIDClass();
//Some command uid
uid.Value = "{E1F29C6B-4E6B-11D2-AE2C-080009EC732A}";
bool addedAcc = pAccTable.Add(uid, System.Convert.ToInt32(System.Windows.Forms.Keys.A), true, false, false) ;
But, if other than the above like you want to execute your own methods, you need to use SetWindowsHookEx win32 api and global hooking keyboards event. This is the sample,
public class KeyEventsHooker {
private const int WH_KEYBOARD_LL = 13;
private const int WM_KEYDOWN = 0x0100;
[StructLayout(LayoutKind.Sequential)]
public struct KBDLLHOOKSTRUCT {
public ushort KeyCode;
public ushort Scan;
public uint Flags;
public uint Time;
public IntPtr ExtraInfo;
}
[DllImport("user32.dll", CharSet = CharSet.Auto,
CallingConvention = CallingConvention.StdCall)]
public static extern int SetWindowsHookEx(int idHook, HookProc lpfn,
IntPtr hInstance, int threadId);
[DllImport("user32.dll", CharSet = CharSet.Auto,
CallingConvention = CallingConvention.StdCall)]
public static extern bool UnhookWindowsHookEx(int idHook);
[DllImport("user32.dll", CharSet = CharSet.Auto,
CallingConvention = CallingConvention.StdCall)]
public static extern int CallNextHookEx(int idHook, int nCode,
IntPtr wParam, ref KBDLLHOOKSTRUCT lParam);
private int hHook = 0;
public delegate int HookProc(int nCode, IntPtr wParam, ref KBDLLHOOKSTRUCT lParam);
public event Action<System.Windows.Forms.Keys> OnKeyDown;
public void Hook() {
hHook = SetWindowsHookEx(WH_KEYBOARD_LL, new HookProc(KeyHookProc), IntPtr.Zero, 0);
}
public void Unhook() {
UnhookWindowsHookEx(hHook);
}
private int KeyHookProc(int nCode, IntPtr wParam, ref KBDLLHOOKSTRUCT lParam) {
if (nCode < 0) {
return CallNextHookEx(hHook, nCode, wParam, ref lParam);
}
else {
switch (wParam.ToInt32()) {
case WM_KEYDOWN:
if (OnKeyDown != null) {
OnKeyDown((System.Windows.Forms.Keys)lParam.KeyCode);
}
break;
}
return CallNextHookEx(hHook, nCode, wParam, ref lParam);
}
}
}
And, you could hook in your DockableWindow Class like this,
public DockableWindow1(object hook) {
InitializeComponent();
this.Hook = hook;
_keyEventsHooker = new KeyEventsHooker();
_keyEventsHooker.Hook();
_keyEventsHooker.OnKeyDown += new Action<Keys>(_keyEventsHooker_OnKeyDown);
}
You should consider that this sample is ignoring such as shift, alt and ctrl keys. But it is not a basis of GIS, so I will omit these parts.