dieangel Posted April 30, 2009 Share Posted April 30, 2009 Hello everyone, i've been using AutoHotkey for a while not really by choice but because i had nothing better at hand, thing is i'm atracted by Autoit's syntax that looks more "C-ish" and i'm trying to port one of my scripts from one language to the other. Thing is it has become a huuge plate of spagetti with a lot of functions i'm not using anymore aswell as less than optimal elements. I've hit a major roadblock so far it seems i'm unable to find a good replacement for this: NumpadIns:: is_pressed( true ) NumpadIns up:: is_pressed( false ) Wich basically allowed me to call a function when i press a key and another when said key is released, also, it would effectively interupt the keypress from ever reaching the current aplication (it's called a system hook in c# i think) I found the function "HotKeySet("key" [, "function"])" but it doesn't say anywhere how to get also an event triggered on key release. So pardon me for my epic stupidity if it's actually easy to do or documented and i was too stupid to see it... Link to comment Share on other sites More sharing options...
qazwsx Posted April 30, 2009 Share Posted April 30, 2009 polling with _ispressed? Link to comment Share on other sites More sharing options...
Valuater Posted April 30, 2009 Share Posted April 30, 2009 ;;*************** PRESS (END) KEY ***************** #include <Misc.au3> $dll = DllOpen("user32.dll") While 1 Sleep(250) If _IsPressed("23", $dll) Then ToolTip("End Key Pressed ", 10, 10) While _IsPressed("23", $dll) Sleep(10) WEnd ToolTip("End Key Released ", 10, 10) EndIf WEnd DllClose($dll) 8) Link to comment Share on other sites More sharing options...
WideBoyDixon Posted April 30, 2009 Share Posted April 30, 2009 If you want to keep just in one loop then track the status of the key: ;;*************** PRESS (END) KEY ***************** #include <Misc.au3> $dll = DllOpen("user32.dll") Global $fLast = False, $fCurrent While 1 $fCurrent = _IsPressed("23") If $fCurrent <> $fLast Then If $fCurrent Then ToolTip("End Key Pressed", 10, 10) Else ToolTip("End Key Released", 10, 10) EndIF $fLast = $fCurrent EndIf Sleep(10) WEnd DllClose($dll) WBD [center]Wide by name, Wide by nature and Wide by girth[u]Scripts[/u]{Hot Folders} {Screen Calipers} {Screen Crosshairs} {Cross-Process Subclassing} {GDI+ Clock} {ASCII Art Signatures}{Another GDI+ Clock} {Desktop Goldfish} {Game of Life} {3D Pie Chart} {Stock Tracker}[u]UDFs[/u]{_FileReplaceText} {_ArrayCompare} {_ToBase}~ My Scripts On Google Code ~[/center] Link to comment Share on other sites More sharing options...
dieangel Posted May 1, 2009 Author Share Posted May 1, 2009 Thanks for your support guys But it doesn't solve my problem, i need to be able to hook onto the keypress of some keys, so that in the event this key is pressed, i am given the choice to either silently block it or forward it to the application, also it's very time critical, so i would prefer to get some kind of "event" when said key is pressed. pseudocode would be a bit like this: KeypadEnter_Pressed($is_pressed) { $app_is active = IsActiveWindowTheAppIMWatching(); if($is_pressed) { if($app_is active) do_something() else SendKeyToApp(KeypadEnter Down) } else { if($app_is active) do_something_else() else SendKeyToApp(KeypadEnter Up) } } Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now