Sign in to follow this  
Followers 0
Jacobm001

Window Specifc Hotkey

5 posts in this topic

Hello all,

I started learning AHK but it just isn't as powerful as AutoIt so I'm trying to convert over to AutoIt. Unfortunately one thing I was able to do with AHK that I can't figure out how to do in AutoIt is Window/Application specific hotkeys. Is there a way to do this in AutoIt?? If I could get an example that'd be great!.

Example code in AHK:

#IfWinActive ahk_class Notepad

^1:: ;Control + 1

Send You just clicked control + 1

return

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

@Jacobm001

If WinActive("[CLASS:Notepad]","") Then
Send("^1")
Send("you just clicked ctrl+1")
EndIf

Its very similar of autoit,copy ?

Cheers, FireFox.

Edited by FireFox

 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites

Okay i see how that could work. The thing though is that I might want the same hotkey to work for multiple windows. So would I do that with a multiple if statement?

Example:

Func Control1()

IF WinActive("[CLASS:Notepad]", "") Then

Send("blah")

ElseIf WinActive("calc", "") Then

ControlClick("button1")

Else

MsbBox("number", "No set window open")

EndIf

EndFunc

PS I know I'm missing the code this is just the most important part :) Thanks for your help!

Share this post


Link to post
Share on other sites

@Jacobm001,

Use Or statement :

If WinActive("","") Or WinActive("","") Or .... Then

EndIf

 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

... Window/Application specific hotkeys. ...

Welcome to the forums. I've been watching this thread since you first posted and I was not sure what you wanted. Some people want to assign certain key combinations to call User Defined Functions (UDF) - but only if a certain window is active. If a different window is active, they want to assign totally different keys combos to call different functions. If none of the windows of interest are active, then no hotkeys are set.

But - judging from the posts in the thread, you seem to want one combo of hotkeys to do different things based on which window is active. More about that later*.

Since you are new to AutoIt, I'll take this opportunity to point out a minor syntax issue in the code that FireFox posted.

This code...

Send("you just clicked ctrl+1")

...would type this...

you just clicked ctrl!

...into the notepad window

This code...

Send("you just clicked ctrl+1", 1)

...would type this...

you just clicked ctrl+1

...into the notepad window

Because the "+" is a special character representing the shift key. Forgive me if you already knew that from your AHK coding.

... I might want the same hotkey to work for multiple windows. So would I do that with a multiple if statement? ...

Yes; or even "single line" If statements.

Func Control1()

If WinActive("[CLASS:Notepad]", "") Then Send("blah")

If WinActive("calc", "") Then ControlClick("button1")

EndFunc

... PS I know I'm missing the code this is just the most important part :) Thanks for your help! ...

Pseudo code is fine :-)

*If you ever did want HotKeys to be set only if a window was active, you would just put those assignments in a loop that constantly watched for the windows of interests.

I stuck with "If statements" since you went there. You might also want to look into:

Select...Case...EndSelect

Again - welcome.

Edited by herewasplato

[size="1"][font="Arial"].[u].[/u][/font][/size]

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