Sign in to follow this  
Followers 0
Guest goflyapig

Program-Specific Hotkeys ?

4 posts in this topic

#1 ·  Posted (edited)

I'm trying to set a hotkey that only does something in a certain program, and ignores it in other programs, but I couldn't figure it out (is it possible?).

I tried doing something like this:

HotKeySet("^c", "someFunc")

While 1
    Sleep(100)
WEnd

Func someFunc()
    If NOT WinActive("Foo") Then
        Send("^c")
        Return
    EndIf
    ToolTip("You pressed Ctrl+C in Foo", 0, 0)
EndFunc

What I wanted was for Ctrl+C put up a tooltip if the window was named Foo, and otherwise sent Ctrl+C back to the program to do the usual.

What I got was a Stack Overflow, because sending Ctrl+C just caused triggered the hotkey again. Is there a way to do this? :)

Edited by goflyapig

Share this post


Link to post
Share on other sites



Arggh. I figured it out. Nevermind. :)

Share this post


Link to post
Share on other sites

See the HotKeySet Remarks...

There are two techniques:

One:

While 1
If WinActive("Foo") Then
  HotKeySet("^c", "someFunc")
Else
  HotKeySet("^c");un-register hotkey
EndFunc
Wend

Two:

Func someFunc()

If NOT WinActive("Foo") Then

HotKeySet("^c") ;unregister

Send("^c")

HotKeySet("^c", "someFunc") ;re-register

EndIf

EndFunc


Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

To avoid useless activations and deactivations I advice you tring something like:

Global $bHook = 0
AdlibEnable('_keyhooking',250)


Func _keyhooking()
   Select
   Case WinActive("Foo") AND $bHook = 0
      $bHook = 1
      HotKeySet("^c", "someFunc")
   Case Not WinActive("Foo") AND $bHook = 1
      $bHook = 0
      HotKeySet("^c",)
   EndSelect
EndFunc
Edited by ezzetabi

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
Sign in to follow this  
Followers 0