Jacobm001 Posted December 25, 2008 Share Posted December 25, 2008 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 Link to comment Share on other sites More sharing options...
FireFox Posted December 25, 2008 Share Posted December 25, 2008 (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 December 25, 2008 by FireFox Link to comment Share on other sites More sharing options...
Jacobm001 Posted December 25, 2008 Author Share Posted December 25, 2008 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! Link to comment Share on other sites More sharing options...
FireFox Posted December 25, 2008 Share Posted December 25, 2008 @Jacobm001, Use Or statement : If WinActive("","") Or WinActive("","") Or .... Then EndIf Link to comment Share on other sites More sharing options...
herewasplato Posted December 26, 2008 Share Posted December 26, 2008 (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 December 26, 2008 by herewasplato [size="1"][font="Arial"].[u].[/u][/font][/size] 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