c# - Why i can't get to the events of the global keys hooking ? -
i created new form tried before new class same problem. created new form , added:
using system; using system.collections.generic; using system.componentmodel; using system.data; using system.drawing; using system.linq; using system.text; using system.windows.forms; namespace capture { public partial class hook_keys : form { globalkeyboardhook gkh = new globalkeyboardhook(); public bool onoff = false; public hook_keys() { initializecomponent(); } private void hook_keys_load(object sender, eventargs e) { gkh.hookedkeys.add(keys.a); gkh.hookedkeys.add(keys.b); gkh.keydown += new keyeventhandler(gkh_keydown); gkh.keyup += new keyeventhandler(gkh_keyup); } void gkh_keyup(object sender, keyeventargs e) { onoff = true; e.handled = true; } void gkh_keydown(object sender, keyeventargs e) { onoff = false; e.handled = true; } } }
then in class @ top did:
hook_keys hookeys = new hook_keys();
then using it:
if (hookeys.onoff == true) { font.drawtext(null, string.format("{0:n0} fps", this.fps.getfps()), 5, 5, sharpdx.color.red); string timerunning = framespersecond.runtime.tostring(); font.drawtext(null, string.format("{0:n0} time running ", timerunning), 5, 30, sharpdx.color.red); }
the problem it's never getting events gkh_keyup , gkh_keydown in new form.
i must project i'm trying use class library project type.
i tried use before on simple windows forms application without classes or new forms windows forms application in form1 , it's working fine.
i took source code here:
Comments
Post a Comment