Jump to content
jaberwacky

Keyboard hook still calls next hook; how to make it stop

Recommended Posts

jaberwacky

I am making a copy/paste manager to hopefully be used by some people at my workplace.  I use a keyboard hook to both detect instances of ctrl+c which is successful.  I also use it to detect number key presses.  When a number is pressed the highlighted text is then replaced by that number.  I want to not pass on the number to the next hook.  How can I do this?  Sorry, it's been a looooong time since I did any kind of coding.  Here is a pseudocode example.

Func keyboard_hook( ... )
    Switch $ctrl_c
        Case True
            dothings()
    EndSwitch
    
    Switch $key1, $key2, $key3, etc
        Case True
            dostuff()
            
            return 1 <--- still calls the next hook anyway!
    EndSwitch
    
    Return CallnextHook(...)
EndFunc

 

Share this post


Link to post
Share on other sites
jaberwacky
Posted (edited)

I figured it out.

 

Func keyboard_hook( ... )
    Switch $ctrl_c
        Case True
            dothings()
            
            Return CallnextHook(...)
    EndSwitch
    
    Switch $key1, $key2, $key3, etc
        Case True
            dostuff()
    EndSwitch
    
    return 1 
EndFunc

 

Edited by jaberwacky

Share this post


Link to post
Share on other sites
Bilgus
Posted (edited)

you have two keys there on ctrl you need to set a flag and pass through on 'C' you need to check for previous flag do your thing and (probably) send 'C' up & send ctrl UP

Edited by Bilgus

Share this post


Link to post
Share on other sites
Bilgus

See SendKeyLL here: 

you can use that to send your key up events

Share this post


Link to post
Share on other sites
seandisanti

you could just set hotkeys for while the window in question is active, rather than manually casing out keyboard hooks. Look at hotkeyset and GUISetAccelerators as alternatives

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

×