monoscout999 Posted September 6, 2011 Share Posted September 6, 2011 Something like this will replace AHK code, maybe adding some checks to avoid set the HotKey in every cycle of the loop. Global $Classes[4] = ["[CLASS:CabinetWClass]", "[CLASS:ExploreWClass]", "[CLASS:Progman]", "[CLASS:WorkerW]"] While True If _WinActiveClassByArray($Classes) Then _SetHotkey(True) Else _SetHotkey(False) EndIf WEnd Func _SetHotKey($iSet) Switch $iSet Case True HotKeySet("{F1}", "_CreateFolder") Case False HotKeySet("{F1}") EndSwitch EndFunc ;==>_SetHotKey Func _CreateFolder() Send("^+n") EndFunc ;==>_CreateFolder Func _WinActiveClassByArray($aClasses) For $i = 0 To UBound($aClasses) - 1 If WinActive($aClasses[$i]) Then Return True Next Return False EndFunc ;==>_WinActiveClassByArray Link to comment Share on other sites More sharing options...
MilesAhead Posted September 6, 2011 Author Share Posted September 6, 2011 (edited) May work but the other way I also have greater mouse control if I want to use mouse hotkeys. _IsPressed together with picking up a mouse click just does not work as well as #LButton:: for Winkey pluse left click. The AHK code is likely doing the polling in compiled code rather than script. If I want to change from using a keyboard hotkey to a mouse hotkay all I have to do is launch the handler with say "#LButton" string on the command line. It replaces the currently running handler and initializes the new hotkey. In fact on some AutoIt3 apps I have a checked item in the Tray Menu to use a mouse hotkey. Enable launches the mouse handler AHK exe with the hotkey on command line. Disable kill the exe if running. Very simple. In fact I was just using Send in the AHK app. At least now I've figured out a better way with messaging. Plus the slave app can PostMessage with WParam set to 1 to suggest the main app should kill itself due to some error. I don't see the bugaboo about using more than one exe to do something. Edited September 6, 2011 by MilesAhead My Freeware Page Link to comment Share on other sites More sharing options...
monoscout999 Posted September 6, 2011 Share Posted September 6, 2011 When i found an issue like yours(not anymore i think you found your solution) i like to find the solution covering the areas that atoit can´t cover natively. I enjoy to do that. I like this topic, a few ideas come up from here... like the idea to SetHoyKeys for only specific windows.. and do windows check functions like WinExists or WinActive throug a group of windows... and now a way to make an user frendly function to set as HotKey mouse inputs.. Hooking the Mouse is a solution but is not user frendly solution. MilesAhead 1 Link to comment Share on other sites More sharing options...
JohnOne Posted September 6, 2011 Share Posted September 6, 2011 Have you seen this by yashied. AutoIt Absolute Beginners  Require a serial  Pause Script  Video Tutorials by Morthawt  ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
monoscout999 Posted September 6, 2011 Share Posted September 6, 2011 Have you seen this by yashied. Thanks JohnOne that solve the wrong window problem. PD : Why John and not Jhon, i don`t know very much about english names. Link to comment Share on other sites More sharing options...
JohnOne Posted September 6, 2011 Share Posted September 6, 2011 I've no Idea, I cannot say I know anything about names myself. AutoIt Absolute Beginners  Require a serial  Pause Script  Video Tutorials by Morthawt  ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted September 6, 2011 Moderators Share Posted September 6, 2011 (edited) I have no clue how it does it internally. But there's a directive #IfWinActive Hotkeys below that line in the script are only active when the window that fits the directive is active. In this case it's only active when Explorer Window or the Desktop has the focus. An easy way to do it for several class names is to create a group like the one below: GroupAdd,DesktopGroup, ahk_class CabinetWClass GroupAdd,DesktopGroup, ahk_class ExploreWClass GroupAdd,DesktopGroup, ahk_class Progman GroupAdd,DesktopGroup, ahk_class WorkerW and to use the group: #IfWinActive ahk_group DeskTopGroup F7:: do stuff Return The F7 will only "eat" the key if the active window is in DesktTopGroup Also you can process the key and still pass it on using a tilde as in #IfWinActive ahk_group DeskTopGroup ~F7:: do stuff Return You can also set the hotkey using a variable and function call rather than hard wiring it. You can always roll your own "group" types. Here's an example of some things I tend to do with SQLite to treat it like a hash array, but with more options. expandcollapse popup#include <Array.au3> #include <SQLite.au3> #include <SQLite.dll.au3> Global $__gh_Au3GroupAddDB = 0 Global $__gs_SQLiteDBToUse = "";"System.Data.SQLite.dll" For $i = 1 To 220 If Mod($i, 7) = 0 Then _SQLite_Au3GroupAdd("mygroup", "some_class_one", "some_value" & $i) Else _SQLite_Au3GroupAdd("mygroup", "some_class", "some_value" & $i) EndIf Next Global $ga_bygroup = _SQLite_Au3GroupGetValues("mygroup") _ArrayDisplay($ga_bygroup, "by group") Global $ga_byclass = _SQLite_Au3GroupGetValues("mygroup", "some_class") _ArrayDisplay($ga_byclass, "by class") Global $ga_byclassone = _SQLite_Au3GroupGetValues("mygroup", "some_class_one") _ArrayDisplay($ga_byclassone, "by class one") Func _SQLite_Au3GroupAdd($s_group, $s_type, $s_val) Local $s_sql = "" If $__gh_Au3GroupAddDB < 1 Then _SQLite_Startup($__gs_SQLiteDBToUse) $__gh_Au3GroupAddDB = _SQLite_Open(":memory:") If $__gh_Au3GroupAddDB < 1 Then Return SetError(1, 0, 0) EndIf $s_sql = "CREATE TEMP TABLE [Au3_Group] ([Group] TEXT COLLATE NOCASE, " $s_sql &= "[Type] TEXT COLLATE NOCASE, [Value] TEXT COLLATE NOCASE);" If _SQLite_Exec($__gh_Au3GroupAddDB, $s_sql) <> $SQLITE_OK Then Return SetError(2, 0, 0) EndIf EndIf $s_sql = "begin;" $s_sql &= "DELETE FROM Au3_Group " $s_sql &= "WHERE [Group] LIKE '" & StringReplace($s_group, "'", "''", 0, 1) & "' " $s_sql &= "AND [Type] LIKE '" & StringReplace($s_type, "'", "''", 0, 1) & "' " $s_sql &= "AND [Value] LIKE '" & StringReplace($s_val, "'", "''", 0, 1) & "';" $s_sql &= "INSERT INTO Au3_Group VALUES(" $s_sql &= "'" & StringReplace($s_group, "'", "''", 0, 1) & "', " $s_sql &= "'" & StringReplace($s_type, "'", "''", 0, 1) & "', " $s_sql &= "'" & StringReplace($s_val, "'", "''", 0, 1) & "'" $s_sql &= ");" $s_sql &= "commit;" If _SQLite_Exec($__gh_Au3GroupAddDB, $s_sql) <> $SQLITE_OK Then Return SetError(3, 0, 0) EndIf Return 1 EndFunc Func _SQLite_Au3GroupGetValues($s_group, $s_type = "") If $__gh_Au3GroupAddDB < 1 Then Return SetError(1, 0, 0) Local $s_sql = "SELECT Value FROM Au3_Group " $s_sql &= "WHERE [Group] LIKE '" & $s_group & "'" If StringLen($s_type) > 0 Then $s_sql &= " AND [Type] LIKE '" & $s_type & "'" EndIf $s_sql &= ";" Local $i_enum = 100, $i_count = 0, $h_query, $a_res Local $a_ret[$i_enum + 1] _SQLite_Query($__gh_Au3GroupAddDB, $s_sql, $h_query) While _SQLite_FetchData($h_query, $a_res) = $SQLITE_OK $i_count += 1 If $i_count > $i_enum Then $i_enum += 100 ReDim $a_ret[$i_enum + 1] EndIf $a_ret[$i_count] = $a_res[0] WEnd _SQLite_QueryFinalize($h_query) If $i_count = 0 Then Return SetError(2, 0, 0) ReDim $a_ret[$i_count + 1] $a_ret[0] = $i_count Return $a_ret EndFunc With that, you could then make your own UDF functions to handle specifics sort of what like you've been showed, but with more control, and less over all code if you're going to use it often. eg. If _ifWinActive(_SQLite_Au3GroupGetValues("mygroup")) Then ; do something EndIf Func _ifWinActive($v_data, $s_text = "") If Not IsArray($v_data) Then Return WinActive($v_data, $s_text) EndIf For $i = 1 To UBound($v_data) - 1 If WinActive($v_data[$i], $s_text) Then Return 1 Next Return 0 EndFunc Edit: FYI, to use classes, you'd have to create the class strings like this: _SQLite_Au3GroupAdd("mygroup", "some_class", "[CLASS:CabinetWClass]") _SQLite_Au3GroupAdd("mygroup", "some_class", "[CLASS:ExploreWClass]") ;ETC Edited September 12, 2011 by SmOke_N Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
monoscout999 Posted September 6, 2011 Share Posted September 6, 2011 Nice example SmOke very impressive, i never use SQLite before. Link to comment Share on other sites More sharing options...
MilesAhead Posted September 6, 2011 Author Share Posted September 6, 2011 When i found an issue like yours(not anymore i think you found your solution) i like to find the solution covering the areas that atoit can�t cover natively. I enjoy to do that. I like this topic, a few ideas come up from here... like the idea to SetHoyKeys for only specific windows.. and do windows check functions like WinExists or WinActive throug a group of windows... and now a way to make an user frendly function to set as HotKey mouse inputs.. Hooking the Mouse is a solution but is not user frendly solution. I understand. I must have looked at the entry for HotKeySet a zillion times until I noticed that note. Led me onto thinking about other ways to utilize the strengths of various languages and tools. I used to shy away from message based solutions and go more toward kernel objects, like mutex for single instance in other programming languages. But as I mess around I see in some circumstances a message hack can be very simple and supported by just about any client program. It is interesting to take a fresh look at things. My Freeware Page Link to comment Share on other sites More sharing options...
MilesAhead Posted September 6, 2011 Author Share Posted September 6, 2011 Have you seen this by yashied. That's interesting. Thank you. My Freeware Page Link to comment Share on other sites More sharing options...
MilesAhead Posted September 6, 2011 Author Share Posted September 6, 2011 You can always roll your own "group" types. Thanks for the code. I was trying to figure out how to do SQLL awhile back. My Freeware Page 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