-
Posts
96 -
Joined
-
Last visited
Everything posted by Inpho
-
Hi All, I wondered whether I could optimise my array manipulation functions any better and came across a discovery that's new to me. If your array has more rows than columns, then it seems that it's quicker to loop through it column by column rather than row by row. Here is a demonstration with some timing examples: $iArrayRows = 400000 $iArrayCols = 2 $iLoopRows = $iArrayRows - 1 $iLoopColumns = $iArrayCols - 1 _ArrayCreateH() _ArrayCreateH() _ArrayCreateH() _ArrayCreateH() _ArrayCreateH() ConsoleWrite("---------------" & @CRLF) _ArrayCreateV() _ArrayCreateV() _ArrayCreateV() _ArrayCreateV() _ArrayCreateV() Func _ArrayCreateH() Local $aArray[$iArrayRows][$iArrayCols] $hTimer = _Timer_Init() For $i = 1 To $iLoopRows For $ii = 0 To $iLoopColumns $aArray[$i][$ii] = "0000000000" Next Next $hTimer = _Timer_Diff($hTimer) ConsoleWrite(($hTimer / 1000) & @CRLF) EndFunc Func _ArrayCreateV() Local $aArray[$iArrayRows][$iArrayCols] $hTimer = _Timer_Init() For $ii = 0 To $iLoopColumns For $i = 1 To $iLoopRows $aArray[$i][$ii] = "0000000000" Next Next $hTimer = _Timer_Diff($hTimer) ConsoleWrite(($hTimer / 1000) & @CRLF) EndFunc Timings show a good saving with the above array size (has drastically more rows than columns): 1.7250778 1.755863 1.7677521 1.7441728 1.7371205 --------------- 1.453319 1.4538587 1.4681471 1.4888286 1.4498426 I had no idea that there would be a difference but it seems so obvious now. Is this something that everybody has innately known forever and I'm only just finding out now?
-
Doesn't detect when I move the mouse from 1,12 to 11,2. Fixed for my use: Func _MouseInit() Local $_get = MouseGetPos() Return $_get[0] & ";" & $_get[1] EndFunc
-
Forcing two applications to open side by side
Inpho replied to AlvinHu1991's topic in AutoIt GUI Help and Support
I had an issue with Teams where I wouldn't notice a notification - and hours would go by until eventually I get a visit at my desk. This is how I found out someone sent me a message hours ago. Teams' method for notifying you of a message is just terrible. Not sure if this would help - but this ensures that a notification can't be missed; can be midifed for other apps hopefully. Works for my use cases. Teams, specifically, creates a bunch of notifications windows at program start, then just hides and shows them with new params each time it wants to tell you something. Saves creating a whole mini GUI every time I guess. Using this knowledge, I just check for existence of certain text in a tray icon. #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Icon=Teams.ico #AutoIt3Wrapper_Outfile=TeamsNotify.exe #AutoIt3Wrapper_Res_Comment=Sam Coates #AutoIt3Wrapper_Res_Description=Microsoft Teams Notifier #AutoIt3Wrapper_Res_Fileversion=1.0.0.0 #AutoIt3Wrapper_Res_ProductName=Microsoft Teams Notifier #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <WindowsConstants.au3> #include <WinAPISysWin.au3> #include <GuiToolbar.au3> #include <Misc.au3> If _Singleton("TeamsNotify.exe", 1) = 0 Then TraySetState(2) MsgBox(0, "Warning", "TeamsNotify" & " is already running.") Exit EndIf Global $iExit = TrayCreateItem("Exit") Opt("TrayMenuMode", 1) Opt("TrayIconDebug", 1) ;#NoTrayIcon Global $iBrightness = 50 Global $aGui = _NotificationGuiCreate() Global $aColours = _ColourSet() Global $iColours = UBound($aColours) - 1 Global $sTeamsAlive = "Microsoft Teams - Available" Global $sTeamsWaiting = "Microsoft Teams - New activity" $hTray = TraySearch($sTeamsAlive) ConsoleWrite($hTray & @CRLF) Main() Func Main() Local $hWnd Local $nMsg While 1 $nMsg = TrayGetMsg() Switch $nMsg Case $iExit Exit EndSwitch ;$hWnd = WinGetHandle("Microsoft Teams Notification") ;$sText = _GUICtrlToolbar_GetButtonText($hTray, $iTrayTeamsIndex) If TraySearch($sTeamsWaiting) <> -1 Then Do Sleep(250) If TrayGetMsg() = $iExit Then ExitLoop _ScreenFlash($aGui) Until TraySearch($sTeamsWaiting) = -1 EndIf WEnd EndFunc Func TraySearch($sSearch) Local $hSysTray_Handle For $i = 1 To 99 ; Find systray handles $hSysTray_Handle = ControlGetHandle('[Class:Shell_TrayWnd]', '', '[Class:ToolbarWindow32;Instance:' & $i & ']') If @error Then ;MsgBox(16, "Error", "System tray not found") ExitLoop EndIf ; Get systray item count Local $iSysTray_ButCount = _GUICtrlToolbar_ButtonCount($hSysTray_Handle) If $iSysTray_ButCount = 0 Then ;MsgBox(16, "Error", "No items found in system tray") ContinueLoop EndIf Local $aSysTray_ButtonText[$iSysTray_ButCount] ; Look for wanted tooltip For $iSysTray_ButtonNumber = 0 To $iSysTray_ButCount - 1 If $sSearch = _GUICtrlToolbar_GetButtonText($hSysTray_Handle, $iSysTray_ButtonNumber) Then _ Return SetError(0, $i, $iSysTray_ButtonNumber) Next Next Return SetError(1, -1, -1) EndFunc ;==>Get_SysTray_IconText Func _WindowCheck($hWnd) If BitAND(WinGetState($hWnd), 16) <> 0 Or _ BitAND(WinGetState($hWnd), 8) = 0 Or _ BitAND(WinGetState($hWnd), 2) = 0 Or _ BitAND(WinGetState($hWnd), 4) = 0 Then Return(SetError(-1, 0, -1)) Else Return(1) EndIf EndFunc Func _NotificationGuiCreate() Local $aArrayGui[4] $aArrayGui[1] = GUICreate("", @DesktopWidth, @DesktopHeight - 40, 0, 0, $ws_popup, BitOR($ws_ex_transparent, $ws_ex_layered, $ws_ex_topmost), WinGetHandle("Program Manager")) WinSetOnTop($aArrayGui[1], "", 1) GUISetState(@SW_DISABLE, $aArrayGui[1]) _WinAPI_SetLayeredWindowAttributes($aArrayGui[1], 0, $iBrightness) $aArrayGui[2] = GUICreate("", @DesktopWidth, @DesktopHeight - 40, 1920, 0, $ws_popup, BitOR($ws_ex_transparent, $ws_ex_layered, $ws_ex_topmost), WinGetHandle("Program Manager")) WinSetOnTop($aArrayGui[2], "", 1) GUISetState(@SW_DISABLE, $aArrayGui[2]) _WinAPI_SetLayeredWindowAttributes($aArrayGui[2], 0, $iBrightness) $aArrayGui[3] = GUICreate("", @DesktopWidth, @DesktopHeight - 40, 1920 + 1920, 0, $ws_popup, BitOR($ws_ex_transparent, $ws_ex_layered, $ws_ex_topmost), WinGetHandle("Program Manager")) WinSetOnTop($aArrayGui[3], "", 1) GUISetState(@SW_DISABLE, $aArrayGui[3]) _WinAPI_SetLayeredWindowAttributes($aArrayGui[3], 0, $iBrightness) Return($aArrayGui) EndFunc Func _ScreenFlash($aArrayGui) Local $i For $i = 1 To UBound($aArrayGui) - 1 GUISetBkColor($aColours[Random(1, $iColours, 1)], $aArrayGui[$i]) WinSetOnTop($aArrayGui[$i], "", 1) GUISetState(@SW_SHOWNOACTIVATE, $aArrayGui[$i]) Next Sleep(150) For $i = 1 To UBound($aArrayGui) - 1 GUISetState(@SW_HIDE, $aArrayGui[$i]) Next Return (1) EndFunc Func _ColourSet() Local $aColours[15] $aColours[1] = '255' $aColours[2] = '45824' $aColours[3] = '16711680' $aColours[4] = '8421504' $aColours[5] = '0' $aColours[6] = '16711935' $aColours[7] = '65535' $aColours[8] = '16776960' $aColours[9] = '16711830' $aColours[10] = '2588671' $aColours[11] = '16711935' $aColours[12] = '15527148' $aColours[13] = '1905237' $aColours[14] = '9699540' Return($aColours) EndFunc ;==>_RichEditColourSet Quick script for testing: $bAlive = True $iChange = TrayCreateItem("Test") $iExit = TrayCreateItem("Exit") Opt("TrayMenuMode", 1) $nMsg = 0 While 1 $nMsg = TrayGetMsg() Switch $nMsg Case $iChange If $bAlive = True Then TraySetToolTip("Microsoft Teams - New activity") $bAlive = False Else TraySetToolTip("Microsoft Teams - Available") $bAlive = True EndIf Case $iExit Exit EndSwitch WEnd -
@ISI360 I found those settings but I figured that since I've never actually used the toolbar (I'm a hotkey person) I'd prefer to disable it. I'll live with vertical, it's a minimal price to pay for extra vertical space. Thanks 🙂
- 250 replies
-
- isn autoit studio
- isn
-
(and 3 more)
Tagged with:
-
Thanks for this update; DualEditor is a fantastic feature. Also want to play with the Extracode Control. An issue; now that I'm using DualEditor, I'm missing too much vertical screen space. I've tried disabling the Toolbar but it only gives the option to move to the left side of the window. So I tried removing all items in the Toolbar - this makes it revert to default. Is there a way of disabling the Toolbar via a config file?
- 250 replies
-
- isn autoit studio
- isn
-
(and 3 more)
Tagged with:
-
@KaFu Thankyou so much; another few clicks saved. #include <WinAPIFiles.au3> #include <WinAPIHObj.au3> If UBound($CmdLine) < 1 Then $sError = "" For $i = 1 To UBound($CmdLine) - 1 If $CmdLine[$i] = "" Then $sError &= "NONE" & @CRLF Else $sError &= $CmdLine[$i] & @CRLF EndIf Next _Error("This script requires a total of 1 parameters; the params you supplied:" & @CRLF & @CRLF & $sError) EndIf Func _Error($sMsg) ;ConsoleWrite($sMsg & @CRLF) MsgBox(0, "", $sMsg) Exit 1 EndFunc $sRandom = String(Random(11111, 99999, 1)) $sFile = "New script_" & $sRandom & ".au3" $hFile = _WinAPI_CreateFile($sFile, 0, 4, 0) _WinAPI_CloseHandle($hFile) FileWrite($sFile, ClipGet()) ShellExecute($sFile) Will post this "ClipToScript" in my examples/libraries at some point
-
Updated: ClipToScript is my attempt at saving some finger effort. I often copy a bunch of code to the clipboard, right click desktop, click New -> AutoIt v3 Script, Ctrl+A to select template text, then finally paste. Now, I can right-click anywhere and just select "ClipToScript" and will invoke the script below to present me with a SciTE window with your code pasted in. Old: Hi All, Guinness made some fantastic functions which I'm using to modify my Windows context menus. But I've come across an issue which I can't solve myself. The functions: _ShellFile _ShellFolder _ShellAll Give the ability to add an item to the right-click menu when selecting a file or folder. What I want is to add options to the context menu displayed when nothing is selected (e.g. you want to make a New Folder in the current directory so you don't select a file or folder - see image below). This would allow me to have a context menu item called "Clip To Script" which creates a new .au3 file in the current directory, executes (edits) it, then pastes the current contents of the clipboard into SciTE. Can anyone point me towards some clues on adding items to the Windows context menu when neither a file or folder is selected please?
-
I seem to have forgotten how to use virtual listviews... Tried implementing this into a 3 x 10,000 listview (yes, 3 rows, 10k columns) but I seem to have suffered a brainfart. Could you help with an example of using this in a virtual listview please? My attempt: #include <GUIConstantsEx.au3> #include <GuiListView.au3> #include <WindowsConstants.au3> #include <WinAPIvkeysConstants.au3> Global $sHeaders = "" Global $aArrayLog[50][10] For $i = 0 To UBound($aArrayLog) - 1 For $ii = 0 To UBound($aArrayLog, 2) - 1 $aArrayLog[$i][$ii] = "kfjdskfsdhfkjsdhfkdshkj" Next Next _ArrayDisplay($aArrayLog) For $i = 0 To UBound($aArrayLog, 2) - 1 $sHeaders &= $i & "|" Next $sHeaders = StringTrimRight($sHeaders, 1) Global $hGUI = GUICreate("Wandering through ListView (901f)", 460, 500, -1, -1,BitOr($WS_SIZEBOX,$WS_MAXIMIZEBOX,$WS_MINIMIZEBOX) -1) Global $idListView = GUICtrlCreateListView($sHeaders, 15, 60, 430, 400, $LVS_OWNERDATA, BitOr($LVS_EX_FULLROWSELECT,$LVS_EX_DOUBLEBUFFER,$WS_EX_CLIENTEDGE)) Global $hListView = GuiCtrlGetHandle($idListView) Global $g_iColumnCount = _GUICtrlListView_GetColumnCount($idListView) -1 Global $g_iItem = -1, $g_iSubItem = -1 ; item/subitem selected in ListView control Global $idDummy_Dbl_Click = GUICtrlCreateDummy() Global $idDummy_Enter = GUICtrlCreateDummy() Global $aAccelKeys[1][2] = [["{ENTER}", $idDummy_Enter]] GUISetAccelerators($aAccelKeys) GUISetState(@SW_SHOW) GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") $iRows = UBound($aArrayLog) GUICtrlSendMsg( $hListView, $LVM_SETITEMCOUNT, $iRows, 0 ) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE GUIDelete($hGUI) Exit Case $idDummy_Dbl_Click MsgBox($MB_TOPMOST, "Double-click activated cell", _ "Row " & $g_iItem & " / Col " & $g_iSubItem) Case $idDummy_Enter If _WinAPI_GetFocus() = $hListView And $g_iItem > -1 Then MsgBox($MB_TOPMOST, "Enter activated cell", _ "Row " & $g_iItem & " / Col " & $g_iSubItem) EndIf EndSwitch WEnd ;============================================ Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam Local Static $tText = DllStructCreate( "wchar[100]" ) Local Static $pText = DllStructGetPtr( $tText ) Local $tNMHDR, $hWndFrom, $iIDFrom, $iCode $tNMHDR = DllStructCreate($tagNMHDR, $lParam) $hWndFrom = DllStructGetData($tNMHDR, "hWndFrom") $iCode = DllStructGetData($tNMHDR, "Code") Local $tNMHDR2 = DllStructCreate($tagNMLISTVIEW, $lParam) Local $hWndFrom2 = DllStructGetData($tNMHDR2, "hWndFrom") Local $iCode2 = DllStructGetData($tNMHDR2, "Code") Static $bMouseDown = False Switch $hWndFrom Case $hListView Switch $iCode2 Case $LVN_GETDISPINFOW Local $tNMLVDISPINFO = DllStructCreate( $tagNMLVDISPINFO, $lParam ) If BitAND( DllStructGetData( $tNMLVDISPINFO, "Mask" ), $LVIF_TEXT ) Then Local $sItem = $aArrayLog[DllStructGetData($tNMLVDISPINFO,"Item")][DllStructGetData($tNMLVDISPINFO,"SubItem")] DllStructSetData( $tText, 1, $sItem ) DllStructSetData( $tNMLVDISPINFO, "Text", $pText ) DllStructSetData( $tNMLVDISPINFO, "TextMax", StringLen( $sItem ) ) EndIf EndSwitch Switch $iCode Case $NM_CUSTOMDRAW Local $tCustDraw = DllStructCreate($tagNMLVCUSTOMDRAW, $lParam) Local $iDrawStage = DllStructGetData($tCustDraw, "dwDrawStage") If $iDrawStage = $CDDS_PREPAINT Then Return $CDRF_NOTIFYITEMDRAW If $iDrawStage = $CDDS_ITEMPREPAINT Then Return $CDRF_NOTIFYSUBITEMDRAW Local $iItem = DllStructGetData($tCustDraw, "dwItemSpec") Local $iSubItem = DllStructGetData($tCustDraw, "iSubItem") Local $iColor = 0xFF000000 ; this is $CLR_DEFAULT in ColorConstants.au3 If $iItem = $g_iItem And $iSubItem = $g_iSubItem Then $iColor = 0xFFFFC0 ; light blue for 1 subitem (BGR) EndIf DllStructSetData($tCustDraw, "clrTextBk", $iColor) Return $CDRF_NEWFONT Case $LVN_KEYDOWN If $bMouseDown Or $g_iItem = -1 Then Return 1 ; don't process Local $tInfo = DllStructCreate($tagNMLVKEYDOWN, $lParam) Local $iVK = DllStructGetData($tInfo, "VKey") Switch $iVK Case $VK_RIGHT If $g_iSubItem < $g_iColumnCount Then $g_iSubItem += 1 _GUICtrlListView_RedrawItems($hListview, $g_iItem, $g_iItem) EndIf Case $VK_LEFT If $g_iSubItem > 0 Then $g_iSubItem -= 1 _GUICtrlListView_RedrawItems($hListview, $g_iItem, $g_iItem) EndIf Case $VK_SPACE ; spacebar would select the whole row Return 1 EndSwitch Case $NM_RELEASEDCAPTURE $bMouseDown = True Local $iItemSave = $g_iItem Local $aHit = _GUICtrlListView_SubItemHitTest($hListView) $g_iItem = $aHit[0] $g_iSubItem = $aHit[1] If $g_iItem = -1 And $iItemSave > -1 Then _GUICtrlListView_RedrawItems($hListview, $iItemSave, $iItemSave) EndIf Case $LVN_ITEMCHANGED Local $tInfo = DllStructCreate($tagNMLISTVIEW, $lParam) Local $iNewState = DllStructGetData($tInfo, "NewState") Switch $iNewState Case BitOr($LVIS_FOCUSED, $LVIS_SELECTED) $g_iItem = DllStructGetData($tInfo, "Item") _GUICtrlListView_SetItemSelected($hListview, $g_iItem, False) EndSwitch ;_GUICtrlListView_RedrawItems($hListview, $g_iItem, $g_iItem) Case $NM_CLICK, $NM_RCLICK $bMouseDown = False Case $NM_DBLCLK $bMouseDown = False If $g_iItem > -1 Then GUICtrlSendToDummy($idDummy_Dbl_Click) EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY
-
All 6 keys work correctly; the expected row is selected. Also doesn't suffer from slowdown when holding arrow key; tested on 10,000 x 4 LV.
-
Thanks for the script pixelsearch. This same issue happens to me, but I'm on Windows 7 x64 Pro with latest AutoIt. When pressing left or right arrow keys, nothing happens... until I press up or down. When pressing up or down I notice that my previous left/right press is now actioned on. The edits you made have solved it. Subbed 😛
-
Works for me WinSetVolume("Google Chrome", 20)
-
Hi All, A co-worker complained that the side keys on his mouse (back and forward) were getting in the way. This script allows you to disable/re-purpose those buttons. Have only tested with a Delux M618 mouse. Haven't tested under Windows 10. This is the standalone version of the script so it will look ugly. The (cleaner) version we're using has a bunch of server calls and auto-update checks. Please report any problems here; even if you fix them yourself. Learning curve etc. #include <Misc.au3> #include <WinAPI.au3> #include <GuiComboBoxEx.au3> #include <ComboConstants.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> Global $gLastHotKeyPressed = ""; Last Hot key pressed Global $gLastHotKeyType = "" ; Last Hot key pressed type Global Const $MSLLHOOKSTRUCT = $tagPOINT & ";dword mouseData;dword flags;dword time;ulong_ptr dwExtraInfo" Global Const $MOUSETRAPEVENT_DUMMY = "_MouseTrapEvent_Dummy" Global $currentEvent[2] Global $currentDownEvent[2] Global $lastEvent = "" Global $iLBUTTONDOWN = 0 Global $iRBUTTONDOWN = 0 Global $iMBUTTONDOWN = 0 Global $iXBUTTONDOWNNumber = 0 ; 1 or 2 xtra buttons Global $LRClickStatus = 0 Global $RLClickStatus = 0 Global $LRDrag = 0 Global $RLDrag = 0 Global $LMDrag = 0 Global $RMDrag = 0 Global $doubleClickTime = 400 Global $gLastMouseEventPressed = "" ; Added for HotKeySetEx UDF ;Global $gLastHotKeyPressed = ""; Last Hot key pressed Added for HotKeySetEx UDF ;Global $gLastHotKeyType = "" ; Last Hot key pressed type Added for HotKeySetEx UDF ; Mouse On event variables Global $a__MSOE_Events[1][1] Global $a__MSOE_DblClk_Data = __MouseTrapEvent_GetDoubleClickData() $doubleClickTime = $a__MSOE_DblClk_Data[0] + 50 Global $hKey_Proc Global $hM_Module Global $hM_Hook If _Singleton("MouseKeyModifier.exe", 1) = 0 Then MsgBox(0, "Warning", "Mouse Key Modifier is already running.") Exit EndIf TrayTip("MKM", "MouseKeyModifier is running. Click here for options", 30) Global $sHotKeyBack = "" Global $sHotKeyForward = "" Opt("TrayMenuMode", 1) Main() Func Main() HotKeySetEx("{XClick12}", "_FuncDummy", 1) Local $tMsg Local Static $aArray = _MouseKeyModifierTrayCreate() Local Static $cTraySettings = $aArray[1] Local Static $cTrayBehaviour = $aArray[2] Local Static $cTrayBehaviourStandard = $aArray[3] Local Static $cTrayBehaviourCustom = $aArray[4] Local Static $cTrayBehaviourStartup = $aArray[5] Local Static $cTrayQuickDisable = $aArray[6] Local Static $cTrayExit = $aArray[7] Local Static $sCurrentBehaviour = IniRead(@ScriptDir & "\config.ini", "DefaultBehaviour", "Hotkey", "Standard") If $sCurrentBehaviour = "Standard" Then TrayItemSetState($cTrayBehaviourStandard, 1) ElseIf $sCurrentBehaviour = "Custom" Then TrayItemSetState($cTrayBehaviourCustom, 1) _HotKeysSet() ElseIf $sCurrentBehaviour = "Disable" Then TrayItemSetState($cTrayQuickDisable, 1) _HotKeysQuickDisable(True) EndIf While 1 $tMsg = TrayGetMsg() Switch $tMsg Case $cTraySettings TraySetState(2) TrayItemSetState($cTraySettings, 4) _HotKeysUpdateSettingsGuiLoop($sCurrentBehaviour) TraySetState(1) Case $cTrayBehaviourStandard _HotKeysQuickDisable(False) TrayItemSetState($cTrayQuickDisable, 4) TrayItemSetState($cTrayBehaviourStandard, 1) TrayItemSetState($cTrayBehaviourCustom, 4) $sCurrentBehaviour = "Standard" Case $cTrayBehaviourCustom _HotKeysQuickDisable(False) TrayItemSetState($cTrayQuickDisable, 4) TrayItemSetState($cTrayBehaviourStandard, 4) TrayItemSetState($cTrayBehaviourCustom, 1) $sCurrentBehaviour = "Custom" _HotKeysSet() Case $cTrayQuickDisable If BitAND(TrayItemGetState($cTrayQuickDisable), 1) = 1 Then _HotKeysQuickDisable(True) TrayItemSetState($cTrayQuickDisable, 1) TrayItemSetState($cTrayBehaviourStandard, 4) TrayItemSetState($cTrayBehaviourCustom, 4) ElseIf BitAND(TrayItemGetState($cTrayQuickDisable), 4) = 4 Then _HotKeysQuickDisable(False) TrayItemSetState($cTrayQuickDisable, 4) If $sCurrentBehaviour = "Standard" Then TrayItemSetState($cTrayBehaviourStandard, 1) TrayItemSetState($cTrayBehaviourCustom, 4) ElseIf $sCurrentBehaviour = "Custom" Then TrayItemSetState($cTrayBehaviourStandard, 4) TrayItemSetState($cTrayBehaviourCustom, 1) _HotKeysSet() ElseIf $sCurrentBehaviour = "Disable" Then $sCurrentBehaviour = "Standard" TrayItemSetState($cTrayBehaviourStandard, 1) TrayItemSetState($cTrayBehaviourCustom, 4) EndIf EndIf Case $cTrayBehaviourStartup TraySetState(2) If BitAND(TrayItemGetState($cTrayBehaviourStandard), 1) = 1 Then IniWrite(@ScriptDir & "\config.ini", "DefaultBehaviour", "Hotkey", "Standard") MsgBox(0, "Success", "'Standard' set as default at startup.") ElseIf BitAND(TrayItemGetState($cTrayBehaviourCustom), 1) = 1 Then IniWrite(@ScriptDir & "\config.ini", "DefaultBehaviour", "Hotkey", "Custom") MsgBox(0, "Success", "'Custom' set as default at startup.") ElseIf BitAND(TrayItemGetState($cTrayQuickDisable), 1) = 1 Then IniWrite(@ScriptDir & "\config.ini", "DefaultBehaviour", "Hotkey", "Disable") MsgBox(0, "Success", "'Disabled' set as default at startup.") EndIf TraySetState(1) TrayItemSetState($cTrayBehaviourStartup, 4) Case $cTrayExit Exit EndSwitch WEnd EndFunc ;==>Main Func _CheckDeselect($cFrom, $cTo) Local $i For $i = $cFrom To $cTo GUICtrlSetState($i, 4) Next Return (1) EndFunc ;==>_CheckDeselect Func _CheckToString($cCheckWin, $cCheckCtrl, $cCheckAlt, $cCheckShift) Local $sReturn = "" Local $i If GUICtrlRead($cCheckWin) = 1 Then $sReturn &= "#" If GUICtrlRead($cCheckCtrl) = 1 Then $sReturn &= "^" If GUICtrlRead($cCheckAlt) = 1 Then $sReturn &= "!" If GUICtrlRead($cCheckShift) = 1 Then $sReturn &= "+" Return ($sReturn) EndFunc ;==>_CheckToString Func _ComboDeselect($hWnd, $cControl) ControlCommand($hWnd, "", $cControl, "SetCurrentSelection", "-1") Return (1) EndFunc ;==>_ComboDeselect Func _ControlDisable($cFrom, $cTo, $bDisable = True) Local $i For $i = $cFrom To $cTo If $bDisable = True Then GUICtrlSetState($i, 4 + 128) Else GUICtrlSetState($i, 4 + 64) EndIf Next Return (1) EndFunc ;==>_ControlDisable Func _FuncDummy() Return (1) EndFunc ;==>_FuncDummy Func _FuncHotKeyBack() Send($sHotKeyBack) Return (1) EndFunc ;==>_FuncHotKeyBack Func _FuncHotKeyForward() Send($sHotKeyForward) Return (1) EndFunc ;==>_FuncHotKeyForward Func _HotKeysAssign($sMouseButton, $sString) If $sMouseButton = "Back" Then HotKeySetEx("{XClick1}", "_FuncHotKeyBack", 1) HotKeySetEx("{XDClick1}", "_FuncHotKeyBack", 1) ElseIf $sMouseButton = "Forward" Then HotKeySetEx("{XClick2}", "_FuncHotKeyForward", 1) HotKeySetEx("{XDClick2}", "_FuncHotKeyForward", 1) EndIf Return (1) EndFunc ;==>_HotKeysAssign Func _HotKeysUpdateSettingsGuiLoop($sCurrentBehaviour) Local Static $aArray = _MouseKeyModifierSettingsGuiCreate() Local Static $cGui = $aArray[1] Local Static $cComboButton = $aArray[2] Local Static $cCheckWin = $aArray[3] Local Static $cCheckCtrl = $aArray[4] Local Static $cCheckAlt = $aArray[5] Local Static $cCheckShift = $aArray[6] Local Static $cComboCharacter = $aArray[7] Local Static $cCheckDisable = $aArray[8] Local Static $cButtonSave = $aArray[9] Local Static $cButtonCancel = $aArray[10] GUICtrlSetState($cCheckWin, 4) GUICtrlSetState($cCheckCtrl, 4) GUICtrlSetState($cCheckAlt, 4) GUICtrlSetState($cCheckShift, 4) _ComboDeselect($cGui, $cComboButton) _ComboDeselect($cGui, $cComboCharacter) Local $sStringToSave = "", $sButtonToSave = "" Local $iIndex GUISetState(@SW_SHOW, $cGui) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case -3, $cButtonCancel GUISetState(@SW_HIDE, $cGui) Return Case $cComboButton ConsoleWrite(GUICtrlRead($cComboButton) & @CRLF) _ComboDeselect($cGui, $cComboCharacter) _HotKeysUpdateSettingsGuiControls(GUICtrlRead($cComboButton), $cCheckWin, $cCheckCtrl, $cCheckAlt, $cCheckShift, $cComboCharacter) Case $cCheckDisable ConsoleWrite(GUICtrlRead($cCheckDisable) & @CRLF) If GUICtrlRead($cCheckDisable) = 1 Then _ControlDisable($cCheckWin, $cComboCharacter, True) _ComboDeselect($cGui, $cComboCharacter) ElseIf GUICtrlRead($cCheckDisable) = 4 Then _ControlDisable($cCheckWin, $cComboCharacter, False) EndIf Case $cButtonSave $sButtonToSave = GUICtrlRead($cComboButton) If $sButtonToSave = "" Then MsgBox(0, "Error", "You must select a button to modify.", 0, $cGui) ContinueLoop EndIf If GUICtrlRead($cCheckDisable) = 1 Then _HotKeysSaveToFile($sButtonToSave, "{EMPTY}") Else $sStringToSave = _CheckToString($cCheckWin, $cCheckCtrl, $cCheckAlt, $cCheckShift) $iIndex = _GUICtrlComboBox_GetCurSel($cComboCharacter) If $iIndex <> -1 Then $sStringToSave &= GUICtrlRead($cComboCharacter) If $sStringToSave = "" Then $sStringToSave = "{EMPTY}" _HotKeysSaveToFile($sButtonToSave, $sStringToSave) EndIf _CheckDeselect($cCheckWin, $cCheckShift) _CheckDeselect($cCheckDisable, $cCheckDisable) _ComboDeselect($cGui, $cComboButton) _ComboDeselect($cGui, $cComboCharacter) If $sCurrentBehaviour = "Custom" Then _HotKeysSet() EndSwitch WEnd EndFunc ;==>_HotKeysUpdateSettingsGuiLoop Func _HotKeysUpdateSettingsGuiControls($sButton, $cCheckWin, $cCheckCtrl, $cCheckAlt, $cCheckShift, $cComboCharacter) Local $sHotKey = _HotKeysGet($sButton) GUICtrlSetState($cCheckWin, 4) GUICtrlSetState($cCheckCtrl, 4) GUICtrlSetState($cCheckAlt, 4) GUICtrlSetState($cCheckShift, 4) If StringInStr($sHotKey, "#") <> 0 Then GUICtrlSetState($cCheckWin, 1) If StringInStr($sHotKey, "^") <> 0 Then GUICtrlSetState($cCheckCtrl, 1) If StringInStr($sHotKey, "!") <> 0 Then GUICtrlSetState($cCheckAlt, 1) If StringInStr($sHotKey, "+") <> 0 Then GUICtrlSetState($cCheckShift, 1) $sHotKey = StringReplace($sHotKey, "#", "") $sHotKey = StringReplace($sHotKey, "^", "") $sHotKey = StringReplace($sHotKey, "!", "") $sHotKey = StringReplace($sHotKey, "+", "") $sHotKey = StringLower($sHotKey) If $sHotKey <> "" Then If StringLen($sHotKey) > 1 Then Return (SetError(-1, 0, "")) ConsoleWrite($sHotKey & @CRLF) If Asc($sHotKey) < 97 Or Asc($sHotKey) > 122 Then Return (SetError(-2, 0, "")) EndIf Local $iIndex = _GUICtrlComboBox_SelectString($cComboCharacter, $sHotKey) Return (1) EndFunc ;==>_HotKeysUpdateSettingsGuiControls Func _HotKeysGet($sButton) Local $sHotKey = IniRead(@ScriptDir & "\config.ini", $sButton, "Hotkey", "*") If @error Or $sHotKey = "*" Then Return (SetError(-1, 0, "{EMPTY}")) Return ($sHotKey) EndFunc ;==>_HotKeysGet Func _HotKeysQuickDisable($bDisable = True) If $bDisable = True Then HotKeySetEx("{XClick1}", "_FuncDummy", 1) HotKeySetEx("{XClick2}", "_FuncDummy", 1) HotKeySetEx("{XDClick1}", "_FuncDummy", 1) HotKeySetEx("{XDClick2}", "_FuncDummy", 1) Else HotKeySetEx("{XClick1}", "") HotKeySetEx("{XClick2}", "") HotKeySetEx("{XDClick1}", "") HotKeySetEx("{XDClick2}", "") EndIf EndFunc ;==>_HotKeysQuickDisable Func _HotKeysSaveToFile($sMouseButton, $sString) IniWrite(@ScriptDir & "\config.ini", $sMouseButton, "Hotkey", $sString) Return (1) EndFunc ;==>_HotKeysSaveToFile Func _HotKeysSet() Local $sHotKey = _HotKeysGet("Back") If $sHotKey <> "{EMPTY}" Then _HotKeysAssign("Back", $sHotKey) $sHotKeyBack = $sHotKey $sHotKey = _HotKeysGet("Forward") If $sHotKey <> "{EMPTY}" Then _HotKeysAssign("Forward", $sHotKey) $sHotKeyForward = $sHotKey Return (1) EndFunc ;==>_HotKeysSet Func _MouseKeyModifierTrayCreate() Local $aArray[8] = [7] $aArray[1] = TrayCreateItem("Settings") $aArray[2] = TrayCreateMenu("Behaviour") $aArray[3] = TrayCreateItem("Standard", $aArray[2]) $aArray[4] = TrayCreateItem("Custom", $aArray[2]) TrayCreateItem("", $aArray[2]) $aArray[5] = TrayCreateItem("Set at Startup", $aArray[2]) $aArray[6] = TrayCreateItem("Quick disable") $aArray[7] = TrayCreateItem("Exit") Return ($aArray) EndFunc ;==>_MouseKeyModifierTrayCreate Func _MouseKeyModifierSettingsGuiCreate() Local $aArray[11] = [10] $aArray[1] = GUICreate("Settings", 276, 171) $aArray[2] = GUICtrlCreateCombo("", 20, 19, 236, 21, BitOR(0x0003, 0x00200000)) GUICtrlSetData(-1, "Back|Forward") $aArray[3] = GUICtrlCreateCheckbox("Win", 20, 54, 38, 20) $aArray[4] = GUICtrlCreateCheckbox("Ctrl", 65, 54, 38, 20) $aArray[5] = GUICtrlCreateCheckbox("Alt", 110, 54, 38, 20) $aArray[6] = GUICtrlCreateCheckbox("Shift", 155, 54, 41, 20) GUICtrlCreateLabel("", 20, 87, 237, 1, 0x10, -1) GUICtrlSetBkColor(-1, "-2") $aArray[7] = GUICtrlCreateCombo("", 207, 53, 50, 21, BitOR(0x0003, 0x00200000)) GUICtrlSetData(-1, _AlphabetGenerate()) $aArray[8] = GUICtrlCreateCheckbox("Disable button", 96, 100, 86, 20) $aArray[9] = GUICtrlCreateButton("Save", 20, 134, 76, 25) $aArray[10] = GUICtrlCreateButton("Cancel", 181, 134, 76, 25) Return ($aArray) EndFunc ;==>_MouseKeyModifierSettingsGuiCreate Func _AlphabetGenerate($sSeparator = "|") Local $sReturn = "" Local $i For $i = 97 To 122 $sReturn &= Chr($i) If $i <> 122 Then $sReturn &= $sSeparator Next ConsoleWrite($sReturn & @CRLF) Return ($sReturn) EndFunc ;==>_AlphabetGenerate Func HotKeySetEx($hotkey, $fun, $block = 1) ; default 1 block 0 intercept allow normal behavour and only for mouse events ; if the the hot key name contains the word CLICK then its a mouse button. If StringInStr(StringUpper($hotkey), "CLICK") > 0 Then ; Mouse hot key Dim $mouseHotKey ; local $mouseHotKey = $hotkey $mouseHotKey = StringReplace($mouseHotKey, "{", "") ; remove { } for mousetrap interface $mouseHotKey = StringReplace($mouseHotKey, "}", "") If $fun = "" Then _MouseTrapEvent($mouseHotKey) ; deregister Else _MouseTrapEvent($mouseHotKey, $fun, $block) ; 1 = block action and redirect to $fun EndIf Else HotKeySet($hotkey, $fun) ; normal AutoIt EndIf EndFunc ;==>HotKeySetEx Func getLastHotKey() ; call this in your function. Equivalent to @HotKeyPressed see example script setLastHotKey() Return $gLastHotKeyPressed ; EndFunc ;==>getLastHotKey Func getLastHotKeyType() ; call this in your function. Optional if you want type KEYBOARD or MOUSE setLastHotKey() Return $gLastHotKeyType ; EndFunc ;==>getLastHotKeyType Func setLastHotKey() ; Dim $sLastMouseEventPressed $sLastMouseEventPressed = __MouseTrapEvent_getLastMouseEventPressed() If $sLastMouseEventPressed <> "" Then $gLastHotKeyPressed = "{" & $sLastMouseEventPressed & "}" $gLastHotKeyType = "Mouse" Else $gLastHotKeyPressed = @HotKeyPressed $gLastHotKeyType = "Keyboard" EndIf Return $gLastHotKeyPressed ; EndFunc ;==>setLastHotKey ; #FUNCTION# ==================================================================================================== ; Name...........: _MouseTrapEvent ; Description....: Set an events handler (a hook) for Mouse device based on MouseSetEvent.udf. ; Syntax.........: _MouseTrapEvent($iEvent, $sFuncName = "", $hTargetWnd = 0, $iBlockDefProc = -1, $vParam = "") ; Parameters.....: $sEvent - The event to set, here is the list of ; supported event stings:- Case InSensitive! ; ; single clicks ; LClick - left button click (Primary) ; MClick - middle button click (Wheel click) ; RClick - right button click (Secondary) ; XClick1 - Xtra button 1 click (usually 'back navigaton') ; XClick2 - Xtra button 2 click (usually 'forward navigaton') ; double clicks ; LDClick - left button (Primary) ; MDClick - middle button (Wheel click) ; RDClick - right button (Secondary) ; XDClick1 - Xtra button 1 (usually 'back navigaton') ; XDClick2 - Xtra button 2 (usually 'forward navigaton') ; psuedo double clicks ('chords') - ; XClick12 - Xtra button 1&2 pressed at the same time. ; ; OTHER EVENTS you'll have to work out yourself eg mouse wheel scroll - see code. ; $sFuncName - [Optional] Function name to call when the event is triggered. ; If this parameter is empty string ("") or omited, the function will *unset* the $iEvent. ; ; $iBlockDefProc - [Optional] Defines if the up event should be blocked (actualy block the mouse action). ; If this parameter = ; -1 (default), user defined event function defines whether to block or not ; 1 (call function and block) ; 0 (call function and continue normal mouse behaviour). ; Note for all click and double click events the down event is always blocked to prevent hanging. ; ; ; $vParam - [Optional] Parameter to pass to the event function ($sFuncName). ; ; Return values..: Success - If the event is set in the first time, or when the event is unset properly, the return is 1, ; if it's set on existing event, the return is 2. ; Failure - Returns 0 on UnSet event mode when there is no set events yet. ; Author.........: credits G.Sandler (Mr)CreatoR ; Remarks........: ; 2) Blocking of $sFuncName function by window messages with commands ; such as "Msgbox()" can lead to unexpected behavior, the return to the system should be as fast as possible! ; Related........: MouseSetEvent.udf ; Link...........: ; Example........: Yes. ; =============================================================================================================== Func _MouseTrapEvent($iEvent, $sFuncName = "", $iBlockDefProc = -1, $vParam = "") Local $i Local $iUserEventCount = 0 Local $hTargetWnd = 0 ; not used $iEvent = StringReplace(StringUpper($iEvent), "CLICK", "Click") ; make case insensitive, to do Drag and Wheel and Up Down If $sFuncName = "" Then ;Unset Event If $a__MSOE_Events[0][0] < 1 Then Return 0 EndIf Local $aTmp_Mouse_Events[1][1] = [[0]] For $i = 1 To $a__MSOE_Events[0][0] ; keep events that don't match or internal dummy events used for double clicks. If $a__MSOE_Events[$i][0] <> $iEvent Or $a__MSOE_Events[$i][1] = $MOUSETRAPEVENT_DUMMY Then $aTmp_Mouse_Events[0][0] += 1 ReDim $aTmp_Mouse_Events[$aTmp_Mouse_Events[0][0] + 1][5] $aTmp_Mouse_Events[$aTmp_Mouse_Events[0][0]][0] = $a__MSOE_Events[$i][0] $aTmp_Mouse_Events[$aTmp_Mouse_Events[0][0]][1] = $a__MSOE_Events[$i][1] $aTmp_Mouse_Events[$aTmp_Mouse_Events[0][0]][2] = $a__MSOE_Events[$i][2] $aTmp_Mouse_Events[$aTmp_Mouse_Events[0][0]][3] = $a__MSOE_Events[$i][3] $aTmp_Mouse_Events[$aTmp_Mouse_Events[0][0]][4] = $a__MSOE_Events[$i][4] If $a__MSOE_Events[$i][1] <> $MOUSETRAPEVENT_DUMMY Then $iUserEventCount += 1 EndIf EndIf Next $a__MSOE_Events = $aTmp_Mouse_Events If $iUserEventCount < 1 Then __MouseTrapEvent_Close() EndIf Return 1 EndIf ;First event If $a__MSOE_Events[0][0] < 1 Then ;Register callback $hKey_Proc = DllCallbackRegister("_MouseTrapEvent_MouseProc", "int", "int;ptr;ptr") $hM_Module = DllCall("kernel32.dll", "hwnd", "GetModuleHandle", "ptr", 0) $hM_Hook = DllCall("user32.dll", "hwnd", "SetWindowsHookEx", "int", $WH_MOUSE_LL, "ptr", DllCallbackGetPtr($hKey_Proc), "hwnd", $hM_Module[0], "dword", 0) EndIf ;Search thru events, and if the event already set, we just (re)set the new function and other parameters For $i = 1 To $a__MSOE_Events[0][0] If $a__MSOE_Events[$i][0] = $iEvent Then If $sFuncName = $MOUSETRAPEVENT_DUMMY Then ; event already handled by user - no need for dummy event Return 1 EndIf $a__MSOE_Events[$i][0] = $iEvent $a__MSOE_Events[$i][1] = $sFuncName $a__MSOE_Events[$i][2] = $hTargetWnd $a__MSOE_Events[$i][3] = $iBlockDefProc $a__MSOE_Events[$i][4] = $vParam Return 2 EndIf Next $a__MSOE_Events[0][0] += 1 ReDim $a__MSOE_Events[$a__MSOE_Events[0][0] + 1][5] $a__MSOE_Events[$a__MSOE_Events[0][0]][0] = $iEvent $a__MSOE_Events[$a__MSOE_Events[0][0]][1] = $sFuncName $a__MSOE_Events[$a__MSOE_Events[0][0]][2] = $hTargetWnd $a__MSOE_Events[$a__MSOE_Events[0][0]][3] = $iBlockDefProc $a__MSOE_Events[$a__MSOE_Events[0][0]][4] = $vParam ; if double click event - attempt to register a dummmy event for single click if one dosen't exist- to prevent hanging If StringInStr($iEvent, "DClick") > 0 Then _MouseTrapEvent(StringReplace($iEvent, "DClick", "Click"), $MOUSETRAPEVENT_DUMMY, 0, 0) EndIf ; if multi button click event - attempt to register a dummmy single click event for each button - to prevent hanging If $iEvent = "XClick12" Then _MouseTrapEvent("XClick1", $MOUSETRAPEVENT_DUMMY, 0, 0) _MouseTrapEvent("XClick2", $MOUSETRAPEVENT_DUMMY, 0, 0) EndIf Return 1 EndFunc ;==>_MouseTrapEvent Func _MouseTrapEvent_Dummy() ; dummy function for unregistered click events of double clicks Return 0; EndFunc ;==>_MouseTrapEvent_Dummy Func _MouseTrapEvent_MouseProc($nCode, $wParam, $lParam) Local $info, $mouseData, $time, $timeDiff If $nCode < 0 Then $ret = DllCall("user32.dll", "long", "CallNextHookEx", "hwnd", $hM_Hook[0], _ "int", $nCode, "ptr", $wParam, "ptr", $lParam) Return $ret[0] EndIf $info = DllStructCreate($MSLLHOOKSTRUCT, $lParam) $mouseData = DllStructGetData($info, 3) $time = DllStructGetData($info, 5) $timeDiff = $time - $currentEvent[1] Select Case $wParam = $WM_MOUSEMOVE ;Test for Drag in here If $currentEvent[0] <> "LDrag" Or $currentEvent[0] <> "LRDrag" Or $currentEvent[0] <> "LMDrag" Then If $iLBUTTONDOWN = 1 Then $currentEvent[0] = "LDrag" If $iRBUTTONDOWN = 1 Then $currentEvent[0] = "LRDrag" $LRDrag = 2 EndIf EndIf EndIf If $currentEvent[0] <> "RDrag" Or $currentEvent[0] <> "RMDrag" Or $currentEvent[0] <> "LRDrag" Then If $iRBUTTONDOWN = 1 Then $currentEvent[0] = "RDrag" EndIf EndIf If $currentEvent[0] <> "MDrag" Then If $iMBUTTONDOWN = 1 Then $currentEvent[0] = "MDrag" $currentEvent[1] = $time EndIf EndIf If $iRBUTTONDOWN = 1 And $iMBUTTONDOWN = 1 And $currentEvent[0] <> "RMDrag" Then $RMDrag = 2 $currentEvent[0] = "RMDrag" $currentEvent[1] = $time EndIf If $iLBUTTONDOWN = 1 And $iMBUTTONDOWN = 1 And $currentEvent[0] <> "LMDrag" Then $LMDrag = 2 $currentEvent[0] = "LMDrag" $currentEvent[1] = $time EndIf Case $wParam = $WM_MOUSEWHEEL If _WinAPI_HiWord($mouseData) > 0 Then ;Wheel Up $currentEvent[0] = "WheelUp" $currentEvent[1] = $time Else ;Wheel Down $currentEvent[0] = "WheelDown" $currentEvent[1] = $time EndIf Case $wParam = $WM_LBUTTONDOWN ;Register Button Down, check for Right/Left If $currentEvent[0] = "RClick" Then $LRClickStatus = 1 EndIf $iLBUTTONDOWN = 1 $currentDownEvent[0] = 'LClick' Case $wParam = $WM_LBUTTONUP ;Update $iLBUTTONDOWN $iLBUTTONDOWN = 0 $currentDownEvent[0] = '' ;Test for Right/Left Click If $RLClickStatus = 1 And ($timeDiff) < $doubleClickTime Then $currentEvent[0] = "RLClick" $currentEvent[1] = $time EndIf If $lastEvent = "LClick" And ($timeDiff) < $doubleClickTime Then $currentEvent[0] = "LDClick" $currentEvent[1] = $time EndIf ;Test for Drops If $currentEvent[0] = "LDrag" Then $currentEvent[0] = "LDrop" $currentEvent[1] = $time EndIf If $LRDrag = 2 And $iRBUTTONDOWN = 1 Then $LRDrag = 1 ; Denote $LRDrag as still having one button clicked, need to register the drop on RButton up EndIf If $LRDrag = 1 And $iRBUTTONDOWN = 0 Then $currentEvent[0] = "LRDrop" $currentEvent[1] = $time $LRDrag = 0 EndIf If $LMDrag = 2 And $iMBUTTONDOWN = 1 Then $LMDrag = 1 ; Denote $LMDrag as still having one button clicked, need to register the drop on MButton up EndIf If $LMDrag = 1 And $iMBUTTONDOWN = 0 Then $currentEvent[0] = "LMDrop" $currentEvent[1] = $time $LMDrag = 0 EndIf ;Set LClick if other events haven't fired If $currentEvent[1] <> $time Then $currentEvent[0] = "LClick" $currentEvent[1] = $time EndIf ;Negate $LRClickStatus $RLClickStatus = 0 Case $wParam = $WM_RBUTTONDOWN ;Register Button Down If $currentEvent[0] = "LClick" Then $RLClickStatus = 1 EndIf $iRBUTTONDOWN = 1 $currentDownEvent[0] = 'RClick' Case $wParam = $WM_RBUTTONUP ;Test for Left, Right, and Right Doubleclick here ;Update $iRBUTTONDOWN $iRBUTTONDOWN = 0 $currentDownEvent[0] = ''; ;Test for Right/Left Click If $LRClickStatus = 1 And ($timeDiff) < $doubleClickTime Then $currentEvent[0] = "LRClick" $currentEvent[1] = $time EndIf If $lastEvent = "RClick" And ($timeDiff) < $doubleClickTime Then $currentEvent[0] = "RDClick" $currentEvent[1] = $time EndIf ;Test for Drops If $currentEvent[0] = "RDrag" Then $currentEvent[0] = "RDrop" $currentEvent[1] = $time EndIf If $LRDrag = 2 And $iLBUTTONDOWN = 1 Then $LRDrag = 1 ; Denote $LRDrag as still having one button clicked, need to register the drop on RButton up EndIf If $LRDrag = 1 And $iLBUTTONDOWN = 0 Then $currentEvent[0] = "LRDrop" $currentEvent[1] = $time $LRDrag = 0 EndIf If $RMDrag = 2 And $iMBUTTONDOWN = 1 Then $RMDrag = 1 ; Denote $LMDrag as still having one button clicked, need to register the drop on MButton up EndIf If $RMDrag = 1 And $iMBUTTONDOWN = 0 Then $currentEvent[0] = "RMDrop" $currentEvent[1] = $time $RMDrag = 0 EndIf ;Set LClick if other events haven't fired If $currentEvent[1] <> $time Then $currentEvent[0] = "RClick" $currentEvent[1] = $time EndIf ;Negate $LRClickStatus $LRClickStatus = 0 Case $wParam = $WM_MBUTTONDOWN ;Register Button Down $iMBUTTONDOWN = 1 $currentDownEvent[0] = 'MClick' Case $wParam = $WM_MBUTTONUP ;Test for Middle Double Click here ;Update $iRBUTTONDOWN $iMBUTTONDOWN = 0 $currentDownEvent[0] = '' ;Test for Right/Left Click If $lastEvent = "MClick" And ($timeDiff) < $doubleClickTime Then $currentEvent[0] = "MDClick" $currentEvent[1] = $time EndIf ;Test for Drops If $currentEvent[0] = "MDrag" Then $currentEvent[0] = "MDrop" $currentEvent[1] = $time EndIf If $LMDrag = 2 And $iLBUTTONDOWN = 1 Then $LMDrag = 1 ; Denote $LRDrag as still having one button clicked, need to register the drop on RButton up EndIf If $LMDrag = 1 And $iLBUTTONDOWN = 0 Then $currentEvent[0] = "LMDrop" $currentEvent[1] = $time $LMDrag = 0 EndIf If $RMDrag = 2 And $iRBUTTONDOWN = 1 Then $RMDrag = 1 ; Denote $LMDrag as still having one button clicked, need to register the drop on MButton up EndIf If $RMDrag = 1 And $iRBUTTONDOWN = 0 Then $currentEvent[0] = "RMDrop" $currentEvent[1] = $time $RMDrag = 0 EndIf ;Set MClick if other events haven't fired If $currentEvent[1] <> $time Then $currentEvent[0] = "MClick" $currentEvent[1] = $time EndIf Case $wParam = $WM_XBUTTONDOWN $iXBUTTONDOWNNumber = _WinAPI_HiWord($mouseData) $currentDownEvent[0] = 'XClick' & $iXBUTTONDOWNNumber Case $wParam = $WM_XBUTTONUP Local $iXbuttonNumber = _WinAPI_HiWord($mouseData) If ($lastEvent = "XClick1" Or $lastEvent = "XClick2") And ($timeDiff) < $doubleClickTime Then If StringRight($lastEvent, 1) = $iXBUTTONDOWNNumber Then $currentEvent[0] = "XDClick" & $iXbuttonNumber $currentEvent[1] = $time Else $currentEvent[0] = "XClick12" ; both X buttons pressed simultaneously $currentEvent[1] = $time EndIf EndIf ;Set XClick if other events haven't fired If $currentEvent[1] <> $time Then If $iXbuttonNumber > 0 Then ;standard win 2000+ Xtra button pressed, append 1 or 2 to event name $currentEvent[0] = "XClick" & $iXbuttonNumber $currentEvent[1] = $time EndIf EndIf $iXBUTTONDOWNNumber = 0 ; reset $currentDownEvent[0] = '' EndSelect If $currentEvent[0] <> "" Then $lastEvent = $currentEvent[0] EndIf If __MouseTrapEvent_Remap($currentEvent[0]) = 1 Then Return 1; EndIf $ret = DllCall("user32.dll", "long", "CallNextHookEx", "hwnd", $hM_Hook[0], _ "int", $nCode, "ptr", $wParam, "ptr", $lParam) Return $ret[0] EndFunc ;==>_MouseTrapEvent_MouseProc ; local function - not user callable Func __MouseTrapEvent_Remap($sEvent) ;search for event to block For $i = 1 To $a__MSOE_Events[0][0] ;Handle / block down events - done to prevent lock ups If $a__MSOE_Events[$i][0] = $currentDownEvent[0] Then Return 1; block handle event EndIf ; handle click - up events. If $a__MSOE_Events[$i][0] = $sEvent Then ;Handle events Local $iBlockDefProc_Ret = $a__MSOE_Events[$i][3] Local $sFuncName = $a__MSOE_Events[$i][1] $iRet = Call($sFuncName, $sEvent, $a__MSOE_Events[$i][4]) If @error Then $iRet = Call($sFuncName, $sEvent) If @error Then $iRet = Call($sFuncName) EndIf EndIf If $iBlockDefProc_Ret = -1 Then $iBlockDefProc_Ret = $iRet EndIf $currentEvent[0] = "" Return $iBlockDefProc_Ret ;Block default processing (or not :)) EndIf Next Return 0 ; don't bypass EndFunc ;==>__MouseTrapEvent_Remap ; call this from HotKeySetEx for mouse hotkeys. Func __MouseTrapEvent_getLastMouseEventPressed() For $i = 1 To $a__MSOE_Events[0][0] Local $sFuncName = $a__MSOE_Events[$i][1] ; If current event a registered hotkey then it will be the last pressed If $a__MSOE_Events[$i][0] = $currentEvent[0] And $sFuncName <> "" And $sFuncName <> $MOUSETRAPEVENT_DUMMY Then Return $currentEvent[0]; hot key found EndIf Next Return "" EndFunc ;==>__MouseTrapEvent_getLastMouseEventPressed ; called this to shut down without having to deregister all events. Func __MouseTrapEvent_Close() DllCall("user32.dll", "int", "UnhookWindowsHookEx", "hwnd", $hM_Hook[0]) $hM_Hook[0] = 0 DllCallbackFree($hKey_Proc) $hKey_Proc = 0 ; clear all events Dim $a__MSOE_Events[1][1] EndFunc ;==>__MouseTrapEvent_Close Func __MouseTrapEvent_GetDoubleClickData() Local $aRet[3] = _ [ _ RegRead('HKEY_CURRENT_USER\Control Panel\Mouse', 'DoubleClickSpeed'), _ RegRead('HKEY_CURRENT_USER\Control Panel\Mouse', 'DoubleClickWidth'), _ RegRead('HKEY_CURRENT_USER\Control Panel\Mouse', 'DoubleClickHeight') _ ] Local $aGDCT = DllCall('User32.dll', 'uint', 'GetDoubleClickTime') If Not @error And $aGDCT[0] > 0 Then $aRet[0] = $aGDCT[0] EndIf Return $aRet EndFunc ;==>__MouseTrapEvent_GetDoubleClickData
-
Getting serial number from Samsung mobile device without adb
Inpho replied to Inpho's topic in Developer General Discussion
I'm making some progress; this "solution" works on my work PC but I'll have to travel to the workshop to get some technicians to test this tomorrow. I'm doubting this is universal but here it is for now. Returns serials from ALL devices inserted since last logon by the looks of it so an internal exclusion list will have to be added to as it goes along. More testing tomorrow. Global Const $sStripClass = "#{a5dcbf10-6530-11d2-901f-00c04fb951ed}" Global Const $sStripIdentifier = "\??\USB#VID_04E8&PID_6860#" Func DevicesGet() Local $sSubKey = "" Local $sKeys = "" Local $aKeys ; Loop from 1 to 10 times, displaying registry keys at the particular instance value. For $i = 1 To 10 $sSubKey = RegEnumKey("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\USB\VID_04E8&PID_6860", $i) If @error Then ExitLoop $sKeys &= $sSubKey & "," Next If $sKeys <> "" Then $sKeys = StringTrimRight($sKeys, 1) $aKeys = StringSplit($sKeys, ",") EndIf Return($aKeys) EndFunc ;==>Example $aSerials = DevicesGet() For $i = 1 To UBound($aSerials) - 1 $s = RegRead("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\USB\VID_04E8&PID_6860\" & $aSerials[$i] & "\Device Parameters", "SymbolicName") $s = _StringTrimLeft($s, "#", 0, 2) $s = _StringLeft($s, "#") ConsoleWrite($s & @CRLF) Next ; #FUNCTION# ==================================================================================================================== ; Name ..........: _StringTrimLeft ; Description ...: Searches for a string inside a string, then removes everything on the left of that string ; Syntax ........: _StringTrimLeft($sString, $sRemove[, $iCaseSense = 0, $iOccurrence = 1]) ; Parameters ....: $sString - a string value. The string to search inside. ; $sRemove - a string value. The string to search for. ; $iCaseSense - an integer value. Flag to indicate if the operations should be case sensitive. ; $iOccurrence - an integer value. Which occurrence of the substring to find in the string. Use a ; negative occurrence to search from the right side. ; Return values .: Success - String ; Failure - Empty string as returned from StringTrimLeft() ; Author ........: Sam Coates ; =============================================================================================================================== Func _StringTrimLeft($sString, $sRemove, $iCaseSense = 0, $iOccurrence = 1) Return (StringTrimLeft($sString, StringInStr($sString, $sRemove, $iCaseSense, $iOccurrence) + StringLen($sRemove) - 1)) EndFunc ;==>_StringTrimLeft ; #FUNCTION# ==================================================================================================================== ; Name ..........: _StringLeft ; Description ...: Searches for a string inside a string, then removes everything on the right of that string ; Syntax ........: _StringLeft($sString, $sRemove[, $iCaseSense = 0, $iOccurrence = 1]) ; Parameters ....: $sString - a string value. The string to search inside. ; $sRemove - a string value. The string to search for. ; $iCaseSense - an integer value. Flag to indicate if the operations should be case sensitive. ; $iOccurrence - an integer value. Which occurrence of the substring to find in the string. Use a ; negative occurrence to search from the right side. ; Return values .: Success - String ; Failure - Empty string as returned from StringLeft() ; Author ........: Sam Coates ; =============================================================================================================================== Func _StringLeft($sString, $sRemove, $iCaseSense = 0, $iOccurrence = 1) Return (StringLeft($sString, StringInStr($sString, $sRemove, $iCaseSense, $iOccurrence) - 1)) EndFunc ;==>_StringLeft- 3 replies
-
- serial
- portable media player
-
(and 2 more)
Tagged with:
-
Getting serial number from Samsung mobile device without adb
Inpho replied to Inpho's topic in Developer General Discussion
I'm using Win7 to develop the tool, but the tool runs on a mix of Windows 7 and 10 machines. This tool is called Hubble (as it inspects Samsung Galaxy devices heh). I work in the industry and have almost infinite devices to test on (from Galaxy S/S1 to Galaxy Folds) so I'll look into your advice tomorrow as it's almost EOD for me. Thanks for the info- 3 replies
-
- serial
- portable media player
-
(and 2 more)
Tagged with:
-
Hi All, I didn't know where to put this; my apologies if this is the wrong location. When you plug a Samsung mobile device (phone, tablet, etc.) into the USB of a Windows PC, you can right-click the device in My Computer and select Properties. Here, it will show you the correct serial number of the device. Clearly Windows doesn't use adb to get the SN so I'm stuck at how to get the SN without adb and where the device doesn't have a drive letter assigned to it. When I last picked this up, I tried seemingly everything I could from wmi(?) and winmgmts(?) but either it's hidden cloak-and-dagger style or I can't see the forest for the trees... Does anyone know what API Windows uses when getting the serial number of a device Windows calls a Portable Media Player?
- 3 replies
-
- serial
- portable media player
-
(and 2 more)
Tagged with:
-
Custom String, Map, File, and Array functions
Inpho replied to Inpho's topic in AutoIt Example Scripts
Array stuff: ; #FUNCTION# ==================================================================================================================== ; Name ..........: _ArrayFindEmptyRows ; Description ...: Returns an array of indexes (similar to _ArrayFindAll) ready to feed straight into _ArrayDelete. ; Syntax ........: _ArrayFindEmptyRows(Const Byref $aArray[, $iStartRow = 1]) ; Parameters ....: $aArray - [in/out and const] The array to search for empty rows ; $iStartRow - [optional] an integer value. The index to start searching from ; Return values .: Success: - An array of indexes ; Failure - Empty string and @error flag as follows: ; 1 - $aArray is not an array ; 2 - $aArray contains one row ; 3 - $iStartRow is out of bounds ; 4 - No results (unable to find any blank rows) ; Author ........: Sam Coates ; =============================================================================================================================== Func _ArrayFindEmptyRows(ByRef Const $aArray, $iStartRow = 1) If Not IsArray($aArray) Then Return(SetError(-1, 0, "")) ;; Array isn't an array If UBound($aArray) < 2 Then Return(SetError(-2, 0, "")) ;; Array only contains one row Local $i, $ii Local $sResults = "" Local $aReturn Local $iArrayRows = UBound($aArray) - 1 ;; hold the number of rows If $iStartRow > $iArrayRows Then Return(SetError(-3, 0, "")) ;; Check if StartRow isn't out of bounds Local $iArrayColumns = UBound($aArray, 2) ;; hold the number of columns If @error = 2 Then $iArrayColumns = 1 ;; if error, then 1d array If $iArrayColumns = 1 Then ;; if 1d array For $i = $iStartRow To $iArrayRows ;; loop through rows If $aArray[$i] = "" Then $sResults &= $i & ";" ;; if its blank, save the index Next ElseIf $iArrayColumns > 1 Then ;; if 2d array For $i = $iStartRow To $iArrayRows ;; loop through rows For $ii = 0 To $iArrayColumns - 1 ;; loop through columns If $aArray[$i][$ii] <> "" Then ExitLoop ;; if a non-blank is found in any cell on a row, skip to next row If $ii = $iArrayColumns - 1 Then $sResults &= $i & ";" ;; if we reach the end of the columns and still havent found a non-blank, save the index Next Next EndIf If $sResults <> "" Then ;; if we made changes $sResults = StringTrimRight($sResults, 1) ;; strip the final semi-colon Else ;; if we made no changes Return(SetError(-4, 0, "")) ;; No results EndIf $aReturn = StringSplit($sResults, ";") ;; split the final string Return($aReturn) ;; return it EndFunc Example: $aArray = _GenRandomArray() $aArrayRemoveBlanks = _ArrayFindEmptyRows($aArray) _ArrayDelete($aArray, $aArrayRemoveBlanks) Func _GenRandomArray() Local $sFile = @TempDir & "\rnd.txt" Local $aArrayReturn[100000];[10] If FileExists($sFile) = 0 Then For $i = 1 To UBound($aArrayReturn) - 1 ;(Mod($i, 10) = 0) ? ($aArray[$i][0] = (_StringRandom(20, 4)) : ($aArray[$i][0] = "") ;; why won't this work lel If Mod($i, 10) <> 0 Then $aArrayReturn[$i] = _StringRandom(20, 4) Next _FileWriteFromArray($sFile, $aArrayReturn) Else _FileReadToArray($sFile, $aArrayReturn, 1, "|") EndIf Return ($aArrayReturn) EndFunc ;==>_GenRandomArray -
Custom String, Map, File, and Array functions
Inpho replied to Inpho's topic in AutoIt Example Scripts
Scripting Dictionary (Map) functions (_MapOfMaps* stuff for reading all ini sections into a map of maps): #AutoIt3Wrapper_AU3Check_Parameters=-d -w- 1 -w 2 -w 3 -w 4 -w 5 -w 6 #include-once #include <Array.au3> ; #FUNCTION# ==================================================================================================================== ; Name ..........: _MapAddKeyValuePair ; Description ...: ; Syntax ........: _MapAddKeyValuePair($mMap, $sKey, $sValue) ; Parameters ....: $mMap - a map. The map you want to add the key/value pair to. ; $sKey - a string value. ; $sValue - a string value. ; Return values .: None ; Author ........: iamtheky ; =============================================================================================================================== Func _MapAddKeyValuePair($mMap, $sKey, $sValue) If $mMap.Exists($sKey) Then Return (SetError(-1, 0, '"' & $sKey & '"' & ' already exists with a value of ' & '"' & $mMap.Item($sKey) & '"')) Else $mMap.Add($sKey, $sValue) EndIf EndFunc ;==>_MapAddKeyValuePair ; #FUNCTION# ==================================================================================================================== ; Name ..........: _MapAppendToKey ; Description ...: ; Syntax ........: _MapAppendToKey($mMap, $sKey, $sValue) ; Parameters ....: $mMap - a map. The map you want to modify the key/value pair in. ; $sKey - a string value. The key you want to append the value to. ; $sValue - a string value. The value you want to append to the key. ; Return values .: None ; Author ........: iamtheky ; =============================================================================================================================== Func _MapAppendToKey($mMap, $sKey, $sValue) Local $sCurrent If $mMap.Exists($sKey) Then $sCurrent = $mMap.Item($sKey) $mMap.Remove($sKey) $mMap.Add($sKey, $sCurrent & ";" & $sValue) Else $mMap.Add($sKey, $sValue) EndIf EndFunc ;==>_MapAppendToKey ; #FUNCTION# ==================================================================================================================== ; Name ..........: _MapFrom2DArray ; Description ...: ; Syntax ........: _MapFrom2DArray($aArray) ; Parameters ....: $aArray - an array of unknowns. ; Return values .: None ; Author ........: iamtheky ; =============================================================================================================================== Func _MapFrom2DArray($aArray) Local $mMap = ObjCreate("Scripting.Dictionary") If Not IsObj($mMap) Then Return (SetError(-1, 0, "Object not created")) EndIf For $i = 0 To UBound($aArray) - 1 _MapAddKeyValuePair($mMap, $aArray[$i][0], $aArray[$i][1]) Next Return ($mMap) EndFunc ;==>_MapFrom2DArray ; #FUNCTION# ==================================================================================================================== ; Name ..........: _MapFromIniSection ; Description ...: ; Syntax ........: _MapFromIniSection($sFile, $sSection) ; Parameters ....: $sFile - a string value. ; $sSection - a string value. ; Return values .: None ; Author ........: iamtheky ; =============================================================================================================================== Func _MapFromIniSection($sFile, $sSection) Local $mMap = _MapInit() Local $aArray = IniReadSection($sFile, $sSection) For $i = 1 To UBound($aArray) - 1 $mMap.Add($aArray[$i][0], $aArray[$i][1]) Next Return ($mMap) EndFunc ;==>_MapFromIniSection ; #FUNCTION# ==================================================================================================================== ; Name ..........: _MapGetValue ; Description ...: ; Syntax ........: _MapGetValue($mMap, $sKey) ; Parameters ....: $mMap - a map. The map you want to get the value from. ; $sKey - a string value. ; Return values .: None ; Author ........: iamtheky ; =============================================================================================================================== Func _MapGetValue($mMap, $sKey) Return ($mMap.Item($sKey)) EndFunc ;==>_MapGetValue ; #FUNCTION# ==================================================================================================================== ; Name ..........: _MapInit ; Description ...: ; Syntax ........: _MapInit() ; Parameters ....: ; Return values .: None ; Author ........: iamtheky ; =============================================================================================================================== Func _MapInit() Local $mMap = ObjCreate("Scripting.Dictionary") If Not IsObj($mMap) Then Return (SetError(-1, 0, "Object not created")) EndIf Return ($mMap) EndFunc ;==>_MapInit ; #FUNCTION# ==================================================================================================================== ; Name ..........: _MapOfMapsFromIni ; Description ...: ; Syntax ........: _MapOfMapsFromIni($sFile) ; Parameters ....: $sFile - a string value. ; Return values .: None ; Author ........: Sam Coates ; =============================================================================================================================== Func _MapOfMapsFromIni($sFile) Local $mMap = _MapInit() Local $mMapScratch Local $sError Local $aSections = IniReadSectionNames($sFile) For $i = 1 To UBound($aSections) - 1 $mMapScratch = _MapFromIniSection($sFile, $aSections[$i]) $sError = _MapAddKeyValuePair($mMap, $aSections[$i], $mMapScratch) If @error Then ConsoleWrite($sError & @CRLF) ContinueLoop EndIf Next Return ($mMap) EndFunc ;==>_MapOfMapsFromIni ; #FUNCTION# ==================================================================================================================== ; Name ..........: _MapOfMapsGetMap ; Description ...: ; Syntax ........: _MapOfMapsGetMap($mMap, $sMapChildName) ; Parameters ....: $mMap - a map. The map you want to extract the map from. ; $sMapChildName - a string value. The name of the map you want to extract. ; Return values .: None ; Author ........: Sam Coates ; =============================================================================================================================== Func _MapOfMapsGetMap($mMap, $sMapChildName) Local $mReturn = _MapGetValue($mMap, $sMapChildName) Return ($mReturn) EndFunc ;==>_MapOfMapsGetMap ; #FUNCTION# ==================================================================================================================== ; Name ..........: _MapOfMapsGetValue ; Description ...: ; Syntax ........: _MapOfMapsGetValue($mMap, $sMapChildName, $sKey) ; Parameters ....: $mMap - a map. The map which holds the maps. ; $sMapChildName - a string value. The name of the map which holds the key/value pairs. ; $sKey - a string value. The name of the key which you want to retrieve the value from. ; Return values .: None ; Author ........: Sam Coates ; =============================================================================================================================== Func _MapOfMapsGetValue($mMap, $sMapChildName, $sKey) Local $sReturn = _MapGetValue(_MapGetValue($mMap, $sMapChildName), $sKey) Return ($sReturn) EndFunc ;==>_MapOfMapsGetValue ; #FUNCTION# ==================================================================================================================== ; Name ..........: _MapOfMapsToString ; Description ...: ; Syntax ........: _MapOfMapsToString($mMap) ; Parameters ....: $mMap - a map. The map which holds the maps. ; Return values .: None ; Author ........: Sam Coates ; =============================================================================================================================== Func _MapOfMapsToString($mMap) Local $sReturn = "" For $sKey In $mMap.Keys $sReturn &= "[" & $sKey & "]" & @CRLF & _MapToString(_MapGetValue($mMap, $sKey), True) & @CRLF & @CRLF Next Return ($sReturn) EndFunc ;==>_MapOfMapsToString ; #FUNCTION# ==================================================================================================================== ; Name ..........: _MapReassignKey ; Description ...: ; Syntax ........: _MapReassignKey($mMap, $sKey, $sValue) ; Parameters ....: $mMap - a map. The map which you want to modify the key/value pair in. ; $sKey - a string value. ; $sValue - a string value. ; Return values .: None ; Author ........: iamtheky ; =============================================================================================================================== Func _MapReassignKey($mMap, $sKey, $sValue) If $mMap.Exists($sKey) Then $mMap.Remove($sKey) $mMap.Add($sKey, $sValue) Else $mMap.Add($sKey, $sValue) EndIf EndFunc ;==>_MapReassignKey ; #FUNCTION# ==================================================================================================================== ; Name ..........: _MapRemoveKey ; Description ...: ; Syntax ........: _MapRemoveKey($mMap, $sKey) ; Parameters ....: $mMap - a map. The map which you want to remove the key/value pair from. ; $sKey - a string value. ; Return values .: None ; Author ........: iamtheky ; =============================================================================================================================== Func _MapRemoveKey($mMap, $sKey) $mMap.Remove($sKey) EndFunc ;==>_MapRemoveKey ; #FUNCTION# ==================================================================================================================== ; Name ..........: _MapTo2dArray ; Description ...: ; Syntax ........: _MapTo2dArray($mMap) ; Parameters ....: $mMap - a map. The map you want to export to a 2D array. ; Return values .: None ; Author ........: iamtheky ; =============================================================================================================================== Func _MapTo2dArray($mMap, $iStartIndex = 1) If $iStartIndex < 0 Or $iStartIndex > 1 Then Return(SetError(-1, 0, -1)) Local $aArray[$mMap.Count + $iStartIndex][2] If $iStartIndex = 1 Then $aArray[0][0] = $mMap.Count For $sKey In $mMap.Keys $aArray[$iStartIndex][0] = $sKey $aArray[$iStartIndex][1] = $mMap.Item($sKey) $iStartIndex += 1 Next Return ($aArray) EndFunc ;==>_MapTo2dArray ; #FUNCTION# ==================================================================================================================== ; Name ..........: _MapToArray ; Description ...: ; Syntax ........: _MapToArray($mMap) ; Parameters ....: $mMap - a map. The map you want to export to an array. ; Return values .: None ; Author ........: iamtheky ; =============================================================================================================================== Func _MapToArray($mMap) Local $aArray[$mMap.Count] Local $i = 0 For $sKey In $mMap.Keys $aArray[$i] = $sKey & " = " & $mMap.Item($sKey) $i += 1 Next Return ($aArray) EndFunc ;==>_MapToArray ; #FUNCTION# ==================================================================================================================== ; Name ..........: _MapToIniSection ; Description ...: ; Syntax ........: _MapToIniSection($mMap, $sSection, $sFile[, $fSort = 0]) ; Parameters ....: $mMap - a map. The map you want to export to an ini section. ; $sSection - a string value. ; $sFile - a string value. ; $fSort - [optional] a floating point value. Default is 0. ; Return values .: None ; Author ........: iamtheky ; =============================================================================================================================== Func _MapToIniSection($mMap, $sSection, $sFile, $fSort = 0) Local $aMap = _MapTo2dArray($mMap) _ArrayInsert($aMap, 0, UBound($aMap) - 1) If $fSort = 1 Then _ArraySort($aMap) IniWriteSection($sFile, $sSection, $aMap) If @error Then Return (SetError(-1, 0, "")) Return (1) EndFunc ;==>_MapToIniSection ; #FUNCTION# ==================================================================================================================== ; Name ..........: _MapToString ; Description ...: ; Syntax ........: _MapToString($mMap[, $bPadding = False]) ; Parameters ....: $mMap - a map. The map you want to export to a string. ; $bPadding - [optional] a boolean value. Whether to pad the values with a tab. Default is False. ; Return values .: None ; Author ........: iamtheky ; Modified ......: Sam Coates ; =============================================================================================================================== Func _MapToString($mMap, $bPadding = False) Local $sPadding If $bPadding = True Then $sPadding = @TAB Local $sReturn = "" For $sKey In $mMap.Keys $sReturn &= $sPadding & $sKey & " = " & $mMap.Item($sKey) & @LF Next Return (StringReplace($sReturn, @LF, "", -1)) EndFunc ;==>_MapToString Examples: $sFile = "" ;; .ini $mConfig = _MapOfMapsFromIni($sFile) $sValue = _MapOfMapsGetValue($mConfig, "Last", "1") ConsoleWrite($sValue & @CRLF) $sValue = _MapOfMapsGetValue($mConfig, "Last", "2") ConsoleWrite($sValue & @CRLF) $sValue = _MapOfMapsGetValue($mConfig, "Last", "3") ConsoleWrite($sValue & @CRLF) msgbox(0, 'Map String - No Sort' , _MapToString($mConfig)) msgbox(0, 'Map String - No Sort' , _MapToString(_MapOfMapsGetMap($mConfig, "Last"))) _ArrayDisplay(_MapTo2dArray($mConfig, 0)) _ArrayDisplay(_MapTo2dArray(_MapOfMapsGetMap($mConfig, "Last"))) $sMaps = _MapOfMapsToString($mConfig) ConsoleWrite($sMaps & @CRLF) Sample .ini: #region Last - Last 10 models updated using Muninn [Last] 1=SM-N976B|EVR|3.13 2=SM-T585|BTU|3.13 3=SM-T295|BTU|3.13 4=SM-G973F|EVR|3.13 5=SM-A600FN|EVR|3.13 6=SM-A202F|EVR|3.13 7=SM-J415FN|BTU|3.13 8=SM-G975F|EVR|3.13 9=SM-G970F|EVR|3.13 10=SM-A510F|EVR|3.13 #endregion #region FlashCountTargets - flash counts that will trigger an email [FlashCountTargets] Amounts=140000|150000|175000|200000|250000|300000|350000|400000|450000|500000|600000|700000|800000|900000|1000000 #endregion #region FlashCountEmails - email addresses used when triggered by FlashCountTargets [FlashCountEmails] Users=melba23|junkew|jchd|water|iamtheky #endregion #region ListType - Top10 for the top 10 used models by hits. Last10 for the Last 10 models assigned by .init [ListType] ListType=Top10 #endregion #region Variants - Key - RadioButton text ;; Value - 2-letter code from .init. Add |Locked to disable the radio from Flash Gui [Variants] Deep Black = DB|Locked La Fleur =LF|Locked Hugo Boss =HB|Locked #endregion -
Hi All, I intend on keeping custom functions/UDFs (works in progress) here; if anyone wants to use any code, feel free. String functions: #AutoIt3Wrapper_AU3Check_Parameters=-d -w- 1 -w 2 -w 3 -w 4 -w 5 -w 6 #include-once ; #FUNCTION# ==================================================================================================================== ; Name ..........: _DateTimeGet ; Description ...: Returns the date and time formatted for use in sortable filenames, logs, listviews, etc. ; Syntax ........: _DateTimeGet(iType = 1[, $bHumanFormat = False]) ; Parameters ....: $iType - [optional] an integer value. Default is 1. ; 1 - Date and time in file-friendly format; 20190115_113756 ; 2 - Date in file-friendly format; 20190115 ; 3 - Time in file friendly format; 113756 ; $bHumanFormat - [optional] a boolean value. Default is False. ; True - Includes slashes in the date and colons in the time with a space inbetween ; False - No slashes or colons included with an underscore inbetween ; Return values .: Success - String ; Failure - Sets @error to non-zero and returns an empty string ; Author ........: Sam Coates ; =============================================================================================================================== Func _DateTimeGet($iType = 1, $bHumanFormat = False) If $iType < 1 Or $iType > 3 Then Return (SetError(-1, 0, "")) ;; Param1: ;; 1 = Date and time in file friendly format: 20190115_113756 ;; 2 = Date in file friendly format: 20190115 ;; 3 = Time in file friendly format: 113756 ;; Param2: ;; True = Use human-readable format: 15/01/2019 11:37:56 Local $sTime = @HOUR & ":" & @MIN & ":" & @SEC Local $sDate = @MDAY & "/" & @MON & "/" & @YEAR If $iType = 1 Then If $bHumanFormat = False Then $sTime = StringReplace($sTime, ":", "") $sDate = StringReplace($sDate, "/", "") $sDate = StringTrimLeft($sDate, 4) & StringMid($sDate, 3, 2) & StringLeft($sDate, 2) Return ($sDate & "_" & $sTime) Else Return ($sDate & " " & $sTime) EndIf ElseIf $iType = 2 Then If $bHumanFormat = False Then $sDate = StringReplace($sDate, "/", "") $sDate = StringTrimLeft($sDate, 4) & StringMid($sDate, 3, 2) & StringLeft($sDate, 2) EndIf Return ($sDate) ElseIf $iType = 3 Then If $bHumanFormat = False Then $sTime = StringReplace($sTime, "/", "") EndIf Return ($sTime) EndIf EndFunc ;==>_DateTimeGet ; #FUNCTION# ==================================================================================================================== ; Name ..........: _FileToFileExtension ; Description ...: Returns a file extension from a filename/FQPN (Fully Qualified Path Name) ; Syntax ........: _FileToFileExtension($sPath) ; Parameters ....: $sPath - a string value. ; Return values .: Success - String ; Failure - Empty string as returned from StringTrimLeft() ; Author ........: Sam Coates ; =============================================================================================================================== Func _FileToFileExtension($sPath) Return (StringTrimLeft($sPath, StringInStr($sPath, ".", 0, -1))) EndFunc ;==>_FileToFileExtension ; #FUNCTION# ==================================================================================================================== ; Name ..........: _FileToFileName ; Description ...: Returns a filename from a FQPN (Fully Qualified Path Name) ; Syntax ........: _FileToFileName($sPath[, $bIncludeExtension = True]) ; Parameters ....: $sPath - a string value. ; $bIncludeExtension - [optional] a boolean value. Default is True. ; Return values .: Success - String ; Failure - Empty string as returned from StringLeft() ; Author ........: Sam Coates ; =============================================================================================================================== Func _FileToFileName($sPath, $bIncludeExtension = True) Local $sReturn = StringTrimLeft($sPath, StringInStr($sPath, "\", 0, -1)) If $bIncludeExtension = False Then $sReturn = StringLeft($sReturn, StringInStr($sReturn, ".", 0, -1) - 1) Return ($sReturn) EndFunc ;==>_FileToFileName ; #FUNCTION# ==================================================================================================================== ; Name ..........: _FileToFilePath ; Description ...: Returns a folder path from a FQPN (Fully Qualified Path Name) ; Syntax ........: _FileToFilePath($sPath) ; Parameters ....: $sPath - a string value. ; Return values .: Success - String ; Failure - Empty string as returned from StringLeft() ; Author ........: Sam Coates ; =============================================================================================================================== Func _FileToFilePath($sPath) Return (StringLeft($sPath, StringInStr($sPath, "\", 0, -1) - 1)) EndFunc ;==>_FileToFilePath ; #FUNCTION# ==================================================================================================================== ; Name ..........: _StringLeft ; Description ...: Searches for a string inside a string, then removes everything on the right of that string ; Syntax ........: _StringLeft($sString, $sRemove[, $iCaseSense = 0, $iOccurrence = 1]) ; Parameters ....: $sString - a string value. The string to search inside. ; $sRemove - a string value. The string to search for. ; $iCaseSense - an integer value. Flag to indicate if the operations should be case sensitive. ; $iOccurrence - an integer value. Which occurrence of the substring to find in the string. Use a ; negative occurrence to search from the right side. ; Return values .: Success - String ; Failure - Empty string as returned from StringLeft() ; Author ........: Sam Coates ; =============================================================================================================================== Func _StringLeft($sString, $sRemove, $iCaseSense = 0, $iOccurrence = 1) Return (StringLeft($sString, StringInStr($sString, $sRemove, $iCaseSense, $iOccurrence) - 1)) EndFunc ;==>_StringLeft ; #FUNCTION# ==================================================================================================================== ; Name ..........: _StringRandom ; Description ...: Returns a string of random characters ; Syntax ........: _StringRandom($iAmount[, $iType = 1]) ; Parameters ....: $iAmount - an integer value. Length of returned string ; $iType - [optional] an integer value. Default is 1. ; 1 - Return digits (0-9) ; 2 - Return hexadecimal (0-9, A - F) ; 3 - Return Alphanumeric upper (0-9, A - Z) ; 4 - Return Alphanumeric (0-9, A - Z, a - z) ; 5 - Return Alpha upper (A - Z) ; 6 - Return Alpha (A - Z, a - z) ; Return values .: Success - String ; Failure - Empty string and @error flag as follows: ; @error : 1 - $iAmount is not a positive integer ; 2 - $iType is out of bounds ; Author ........: Sam Coates ; =============================================================================================================================== Func _StringRandom($iAmount, $iType = 1) If $iAmount < 1 Or IsInt($iAmount) = 0 Then Return (SetError(-1, 0, "")) Local $sString = "" Local $iRandomLow = 1, $iRandomHigh = 62 #Tidy_Off Local Static $aCharId[63] = [0, Chr(48), Chr(49), Chr(50), Chr(51), Chr(52), Chr(53), Chr(54), Chr(55), Chr(56), Chr(57), Chr(65), Chr(66), Chr(67), _ Chr(68), Chr(69), Chr(70), Chr(71), Chr(72), Chr(73), Chr(74), Chr(75), Chr(76), Chr(77), Chr(78), Chr(79), Chr(80), _ Chr(81), Chr(82), Chr(83), Chr(84), Chr(85), Chr(86), Chr(87), Chr(88), Chr(89), Chr(90), Chr(97), Chr(98), Chr(99), _ Chr(100), Chr(101), Chr(102), Chr(103), Chr(104), Chr(105), Chr(106), Chr(107), Chr(108), Chr(109), Chr(110), Chr(111), _ Chr(112), Chr(113), Chr(114), Chr(115), Chr(116), Chr(117), Chr(118), Chr(119), Chr(120), Chr(121), Chr(122)] #Tidy_On If $iType = 1 Then ;; digits: 1 - 10 $iRandomHigh = 10 ElseIf $iType = 2 Then ;; hexadecimal: 1 - 16 $iRandomHigh = 16 ElseIf $iType = 3 Then ;; alnumupper: 1 - 36 $iRandomHigh = 36 ElseIf $iType = 4 Then ;; alnum: 1 - 62 $iRandomHigh = 62 ElseIf $iType = 5 Then ;; alphaupper: 11 - 36 $iRandomLow = 11 $iRandomHigh = 36 ElseIf $iType = 6 Then ;; alpha: 11 = 62 $iRandomLow = 11 $iRandomHigh = 62 Else Return (SetError(-2, 0, "")) EndIf For $i = 1 To $iAmount $sString &= $aCharId[Random($iRandomLow, $iRandomHigh, 1)] ;; append string with corresponding random character from ascii array Next Return ($sString) EndFunc ;==>_StringRandom ; #FUNCTION# ==================================================================================================================== ; Name ..........: _StringTrimLeft ; Description ...: Searches for a string inside a string, then removes everything on the left of that string ; Syntax ........: _StringTrimLeft($sString, $sRemove[, $iCaseSense = 0, $iOccurrence = 1]) ; Parameters ....: $sString - a string value. The string to search inside. ; $sRemove - a string value. The string to search for. ; $iCaseSense - an integer value. Flag to indicate if the operations should be case sensitive. ; $iOccurrence - an integer value. Which occurrence of the substring to find in the string. Use a ; negative occurrence to search from the right side. ; Return values .: Success - String ; Failure - Empty string as returned from StringTrimLeft() ; Author ........: Sam Coates ; =============================================================================================================================== Func _StringTrimLeft($sString, $sRemove, $iCaseSense = 0, $iOccurrence = 1) Return (StringTrimLeft($sString, StringInStr($sString, $sRemove, $iCaseSense, $iOccurrence) + StringLen($sRemove) - 1)) EndFunc ;==>_StringTrimLeft Examples: ConsoleWrite(_StringRandom(100, 6) & @CRLF) ConsoleWrite(_StringTrimLeft("C:\Windows\System32\cmd.exe", "C:\Windows\System32\") & @CRLF) ConsoleWrite(_StringLeft("C:\Windows\System32\cmd.exe", "cmd.exe") & @CRLF) ConsoleWrite(_FileToFileName("C:\Windows\System32\cmd.exe") & @CRLF) ConsoleWrite(_FileToFilePath("C:\Windows\System32\cmd.exe") & @CRLF) ConsoleWrite(_FileToFileExtension("C:\Windows\System32\cmd.exe") & @CRLF) ConsoleWrite(_StringRandom(6, 4) & "-" & _StringRandom(4, 4) & "-" & _StringRandom(4, 4) & "-" & _StringRandom(4, 4) & "-" & _StringRandom(6, 4)& @CRLF)
-
@ISI360 Were you able to test on any other computers? My work and home computers are able to replicate the problem in my previous post 100% of the time. If any other users could give a test to help prove I'm actually just going insane, that'd be beneficial please 😛 Windows 7 x64 ISN 1.09 (20190619)
- 250 replies
-
- isn autoit studio
- isn
-
(and 3 more)
Tagged with:
-
Why AutoIt, and not another language like C# or Python?
Inpho replied to aryan-eliza's topic in Developer General Discussion
I mostly like AutoIt for its ease of teaching. I personally believe a lot of beginner coders (especially older beginners) give up learning early due to a lack of *usable* results in a given time-frame. Telling someone to spend weeks learning about xyz to only come out with a knowledge of variables, operators, keywords etc. doesn't build confidence but oh wait... you can create a banana class and use that... where? (Is it showing that I'm not a proponent of OOPLs?) Inherently, the whole ethic of AutoIt means that within the first week of learning coding from knowing zero, your student has already created a GUI! This is huge IMO. It empowers the beginner and they *know* they can use that GUI for something. I've been using AutoIt solely for some time now, and have a bunch of applications installed on many computers at work. 100+ users per day; Admin dashboards for each app; logging, automated emails, web API calls, FTP usage, Excel and Word manipulation, Android adb interaction, etc etc etc... Not as much as other members here have made, but a complete ground-up re-write of an app that's fit for a corporate environment can take less than a day, including a smidgin of testing! And when you want to delete a project folder, you don't have to be patient with Windows while it hangs on "Calculating time required to delete files...". Code re-usability that doesn't come with the cost of a million dependencies, I could go on all day about why I love AutoIt but I think I'm just preaching to the choir by now 😛 -
Hi M23, hope you're well. I've added the functions from your UDF to my Calltips, and when using them, it highlighted something almost confusing: I've always ignored the second param for _GUIListViewEx_ReadToArray as I pretty much always want a count in [0]. But after comparing the results from Header Mode and Direct Mode parsing when adding Calltips, it seems that the param is named $iStart in the code for the function. If a user was to use Direct Mode when adding Calltips, then the name of the param would imply that it's "which row to start from" rather than "hold count in [0]". A niggly, non-important thing that would be solved if a user was to take a few seconds to look at the function header; just thought I'd highlight it as you're usually nothing but consistent.
-
I seem to have found a way of making ISN crash. Steps to reproduce: 1. Create an ISN project, and use the below code as the source. 2. Press F5 to run the script from inside ISN. 3. Minimise the ISN window. 4. Without switching to any other windows, click the button in the gui that says "Press" ISN has now gone, presumably crashed, but no error message. At step 4, if you switch to other windows between minimising ISN and clicking the Press button, ISN won't crash. It looks like if ISN attempts to be handed focus when minimised, it crashes? $hGui = GUICreate("Test", 500, 500) $hBut = GUICtrlCreateButton("Press", 10, 10, 75, 25) GUISetState() While 1 $nMsg = GUIGetMsg() Switch $nMsg Case -3 Exit Case $hBut _GuiHide($hGui, True) Sleep(1000) _GuiHide($hGui, False) EndSwitch WEnd Func _GuiHide($hGui, $bHide) If $bHide = True Then TraySetState(2) GUISetState(@SW_HIDE, $hGui) ElseIf $bHide = False Then GUISetState(@SW_SHOW, $hGui) TraySetState(1) EndIf EndFunc ;==>_GuiHide
- 250 replies
-
- isn autoit studio
- isn
-
(and 3 more)
Tagged with:
-
Autoit $gui_disable Problem (Help)
Inpho replied to ufukkreis853's topic in AutoIt GUI Help and Support
_GUICtrlListView_BeginUpdate() _GUICtrlListView_EndUpdate() ? EDIT: I see my answer doesn't fit the question properly. @ufukkreis853 Wouldn't it be more logical to leave the listview grey when disabled; so that the message is conveyed to the user that the listview is locked rather than the program being frozen? Personally, I have a few flavours depending on the application: 1. Empty the listview of data and headers so it's just a blank rectangle. 2. As with 1, but with a loading symbol if the operation takes longer than half a second or so. 3. Lock every control. 4. Hide the original control, and show an empty one in its place while necessary. I only do this if removal of data is unnecessary. -
Good point, I mostly share code with my son (hes 12) so I can get in a habit of assuming everyones a pre-teen coder 😂
-
Thanks for sharing. When I was about 13 (I'm mid 30's now) I made a turn-based Command And Conquer style game in RM Basic at school. Randomness of enemy attacks, weighted randomness of success or failure (depending on army sizes), option to "peek" at the enemy's forces to get a rough indication of their size... Was the first big project I had. After a 15 year break in coding, AutoIT really brought it all back. Welcome to AutoIT, and to the forums.