Leaderboard
Popular Content
Showing content with the highest reputation on 01/03/2020 in all areas
-
Stringsplit is the right way to go. My approach to convert the lines would be this one: $header = "GENDER |NAME |MONTHS |UNIT |PAYEMENT |STATUS |" & @CRLF & "----------|----------|----------|----------|----------|----------|" & @CRLF $result = "" $result = extract("MR |BROWN |2,4,5,11 |DOLLAR |100 |DONE |") $result = extract("MRS |BROWN |1,4,7 |DOLLAR |200 |DONE |") ConsoleWrite($result) Func extract($line) $cells = StringSplit($line, "|") ; ConsoleWrite($cells[3]) $months = StringSplit($cells[3], ",") If @error Then $result &= $header & $line Else $result &= $header For $i = 1 To $months[0] $result &= $cells[1] & "|" & $cells[2] & "|" & StringFormat("%10s", StringStripWS($months[$i], 3)) & "|" & $cells[4] & "|" & $cells[5] & "|" & $cells[6] & @CRLF Next EndIf Return $result & @CRLF & @CRLF EndFunc ;==>extraxt2 points
-
CSV file editor
AutoBert reacted to pixelsearch for a topic
Hi everybody The script below (901f) allows to wander easily through a listview, selecting any item or subitem by using the 4 direction keys. The Enter key is also managed and allows to fire an event (as double-click does) With the help of mikell (many thanks !) and after several tests based on 1000 rows & 6 columns, we succeeded to code a clear WM_NOTIFY function, which is simple (though solid) and should be reusable without any modification in other scripts dealing with basic listviews (we didn't use or check any particular style for the listview) Trapping the Enter key has been done by using a dummy control + Accelerators, though we spent the whole last week trapping it in another way, using Yashied's Wsp.dll (without any problem) . Finally we choosed the dummy control option... to have a smaller code. Version 901f (Nov 11, 2019) : the pic below shows how the selected subitem appears, with its specific background colour (light blue) Version 901f code : #include <GUIConstantsEx.au3> #include <GuiListView.au3> #include <WindowsConstants.au3> #include <WinAPIvkeysConstants.au3> Global $hGUI = GUICreate("Wandering through ListView (901f)", 460, 500) Global $idListView = GUICtrlCreateListView _ (" Col 0 | Col 1| Col 2| Col 3", 15, 60, 430, 400) Global $hListView = GuiCtrlGetHandle($idListView) For $iRow = 0 To 99 $sRow = StringFormat("%2s", $iRow) GUICtrlCreateListViewItem( _ "Row " & $sRow & " / Col 0 |" & _ "Row " & $sRow & " / Col 1 |" & _ "Row " & $sRow & " / Col 2 |" & _ "Row " & $sRow & " / Col 3", $idListView) Next 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) GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") GUISetState(@SW_SHOW) 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 $tNMHDR, $hWndFrom, $iIDFrom, $iCode $tNMHDR = DllStructCreate($tagNMHDR, $lParam) $hWndFrom = DllStructGetData($tNMHDR, "hWndFrom") $iCode = DllStructGetData($tNMHDR, "Code") Static $bMouseDown = False, $bNotXP = Not (@OSVersion = "WIN_XP") Switch $hWndFrom Case $hListView 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 If $bNotXP Then _GUICtrlListView_RedrawItems($hListview, $g_iItem, $g_iItem) EndIf Case $VK_LEFT If $g_iSubItem > 0 Then $g_iSubItem -= 1 If $bNotXP Then _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 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 Version 901k (Dec 16, 2019) What started with a simple "wander through listview" has turned now to a functional CSV file editor, which can be useful to modify your CSV files with AutoIt : Here are the instructions to use the script, based on a CSV file starting like this : street,city,zip,state,beds,baths,sq__ft,type,sale_date,price,latitude,longitude 3526 HIGH ST,SACRAMENTO,95838,CA,2,1,836,Residential,Wed May 21 00:00:00 EDT 2008,59222,38.631913,-121.434879 51 OMAHA CT,SACRAMENTO,95823,CA,3,1,1167,Residential,Wed May 21 00:00:00 EDT 2008,68212,38.478902,-121.431028 ... 1) Import options : comma delimited (default) No need to change anything if your CSV is comma delimited (other options are Semicolon delimited, Tab delimited) 2) Import options : First row = headers (default = checked) * Keep it checked if the 1st row of your imported file contains headers (that's the case in our example) * UNcheck it if the 1st row contains data, making listview headers appear like this : Col 0 | Col 1 | Col 2 ... 3) Import your CSV file : Only now the listview will be created dynamically. As soon as it is populated, GUI becomes resizable/maximizable, which can be helpful during modifications of a listview containing many columns. 4) Selection color : light blue (default) You can change the selected cell background color by clicking the "Selection color" button : this will open Windows color picker. 5) Editing a listview cell : done by Enter key (or double-click), this is how the edited cell will appear : * Please note that the edited background color (green in the pic) depends on each computer theme. It is not related to the selected background we discussed in 4) * Validate your modification with Enter key, or cancel the modification (revert) with Escape Key 6) Edit Font size : 15 (default) 15 was good in the precedent pic, the edited cell had its content "RIO LINDA" perfectly aligned with all other cells (on my computer). Here again, the font height required depends on each computer : if you want the edited font to be bigger (or smaller), just use the updown control. 7) Chained Edit ? (default = No) * "No" => when you finish editing a cell (Enter key), the same cell stays selected. * "Horizontally" => If checked, edition will automatically continue with the cell on its right. * "Vertically" => If checked, edition will automatically continue with the cell below. This feature can be very useful when you modify cells of a whole colum (vertically) or cells by row (horizontally) 8 ) Inserting a blank line (not in Gui) : press the "Ins" key : 9) Deleting a line (not in Gui) : press the "Del" key : 10) Export CSV file : Filename automatically suggested for export will be : Filename import & actual date & actual time, for example : Import name = "Sales Results.csv" => suggested Export name = "Sales Results_2019-12-16 16:00:59.csv" Version 901m (Dec 18, 2019) Yesterday, mikell suggested to import the csv file by dropping it directly into the GUI, good idea This new version 901m allows it. Now there are 2 ways to import the csv file : * Import button * Drag and drop into the large droppable zone, as shown in the pic below (this zone will be reused to create the listview at same coords) Version 901n (Dec 20, 2019) As t0nZ got tons of csv files, pipe "|" separated, here is a new version allowing this 4th separator Version 901p (Dec 25, 2019) New functionality : now you can drag headers to reorder columns. It may help some users who need it while editing their file. Exported CSV file will be saved according to the new columns order. Version 901r (Dec 29, 2019) New functionality : Numeric sort on any column (right click on column header) It is recommended to backup (export) your file before sorting, just in case you need a copy of it, unsorted. Version 901s (Dec 30, 2019) 1 functionality added : String sort (right click on column header) Numeric sort is alright in most cases, but sometimes we also need a String sort like shown in the following picture. Both ways of sorting (numeric and string) are found in this new release. Version 901t (Jan 3, 2020) 3 functionalities added Rename Header , Insert Column , Delete Column (right click on column header to display its context menu) Version 901u (Jan 6, 2020) 1 functionality added : Natural sort. Thanks to jchd for the idea and Melba23 for his function ArrayMultiColSort() included in the script. Though this natural sort isn't fully implemented, it should work when numbers precede letters (see pic below or better, try it on the "street" column found in the downloadable csv test file below) Natural sort duration + listview update are fast, maybe because of the new function _BufferCreate() described here and now added to the script. Version 901w (Jan 10, 2020) Two functionalities added : 1) Close File button, which allows to import other csv file(s) during the same session 2) Import speed has been improved because the listview control is now populated directly by an Array and not anymore by GUICtrlCreateListViewItem() This explains why, in this version, there are no more Control id's for listview items, allowing to empty the listview content in a snap with this line of code : _SendMessage($g_hListView, $LVM_DELETEALLITEMS) That's what it took to add the Close File button and import several csv files during the same session, avoiding id leaks. Please report if any issue is encountered. Version 901x (Jan 14, 2020) One minor functionality added : number of rows is now displayed just under the listview, it may be handy sometimes. Other minor changes included (natural sort speed improved) Credits : Many thanks to Czardas for his function _CSVSplit() and guinness for his function _SaveCSV(), guys you did a great job. Thanks to Musashi : your suggestions and time passed on testing beta versions of the script, that was really helpful and challenging. Not sure I would have ended this script without your detailed reports. Mikell : the 1st step above (901f) that we wrote together, it all started from here. Your knowledge and kindness are legendary ! Not forgetting all other persons who were inspiring : LarsJ, Melba23, jpm, that list could be endless... Download link : version 901x - Jan 14, 2020 (minor update on Jan 15) 901x - CSV file editor.au3 Test csv file (986 rows/12cols) : Sacramento real estate transactions.csv1 point -
I'm creating a WebDriver tutorial
SkysLastChance reacted to water for a topic
Internet Explorer is nearly dead, newer versions of Firefox can't any longer be automated using Stilgar's FF UDF. Hence more and more users (including me) need to look at automating Webbrowsers using WebDriver. That's why I have started to create a tutorial in the wiki. It should describe all necessary steps from intallation to usage. I'm still collecting ideas for the tutorial - that's where you come into play. What do you expect to see in such a tutorial? Which browsers should be covered (Firefox, Chrome and Edge are settled)? Any questions for the FAQ? Which (high level) coding examples do you expect (like "How to attach to a running browser instance") ... Like to see your comments ToDo-List: Add "Tools" section and add ChroPath plugin. Done. FAQ: "How to attach to a running browser instance". Done. Explain the difference between iuiautomation, iaccessible, autoit, webdriver. Done. The AutoIt FAQ 40 has been extended. Detailed description of each function. Done Example for "how to deal with downloading". Use function _WD_DownloadFile. Example for "how to deal with popups (alerts, print or save dialog). Use function_WD_AlertRespond to respond to a user prompt. Example for "how to deal with multiple tabs". Use functions _WD_NewTab (create a new tab), _WD_Window (close or switch to a tab) and _WD_Attach (attach to existing tab).1 point -
This allows you to easily redirect your existing RDP session to the console so it will maintain an active Desktop. This code has a UI to perform the redirect, but to actually use it with your automation, you would need to incorporate it into your code as once it's run it will kick you out of the RDP session since it was redirected to the console. When I was using this, I had another automation running in the background so I ran this to redirect to console and my other automation script ran after hours when it was schedule. #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Outfile_type=a3x #AutoIt3Wrapper_Outfile=RedirectToConsole.a3x #AutoIt3Wrapper_UseX64=N #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #cs Make a remote connection not loose access to the desktop after disconnecting. https://support.smartbear.com/testcomplete/docs/testing-with/running/via-rdp/keeping-computer-unlocked.html https://support.microsoft.com/en-us/help/302801/the-use-of-tscon-exe-can-leave-a-previously-locked-console-unlocked for /f "skip=1 tokens=3" %%s in ('query user %USERNAME%') do (%windir%\System32\tscon.exe %%s /dest:console) "C:\<path to dc64.exe>\dc64.exe" -width=1920 -height=1200 -depth=32 for /f "skip=1 tokens=3" %%s in ('query user %USERNAME%') do ( %windir%\System32\tscon.exe %%s /dest:console ) Must be run under x64 not 32, use this to run the execute under 64bit _WinAPI_Wow64EnableWow64FsRedirection(True) ShellExecute(@WindowsDir & '\System32\tscon.exe', '1 /dest:console', '', 'runas') _WinAPI_Wow64EnableWow64FsRedirection(False) Once we have been redirected to console, ensure we are using the largest display available can't tell what the available displays are until we have gone into the console at least once... Create an .ini for use on that computer after to load the dropdown? Default to the last one used, Largest if nothing else was used yet. This doesn't work within Citrix as its a totally different connection type Create a log file to track who initiated the redirect and where they connected in from #ce #include <WinAPIFiles.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <Array.au3> #include <ColorConstants.au3> #include <GuiComboBox.au3> Opt("GUIOnEventMode", 1) ;Use Event mode to call functions directly $sLogFile = @ScriptDir & "\redirect.log" $sSeperator = "---------------------------------------------------------------------------------------------" ;===================================================================================== ;=== Used to figure out what SessionID we are logged in with and if its a remote connection ;===================================================================================== ;Options for the $SessionID Global Static $WTS_CURRENT_SESSION = -1 ;Options for the $WTSInfoClass Global Static $WTSInitialProgram = 0 Global Static $WTSApplicationName = 1 Global Static $WTSWorkingDirectory = 2 Global Static $WTSOEMId = 3 Global Static $WTSSessionId = 4 Global Static $WTSUserName = 5 Global Static $WTSWinStationName = 6 Global Static $WTSDomainName = 7 Global Static $WTSConnectState = 8 Global Static $WTSClientBuildNumber = 9 Global Static $WTSClientName = 10 Global Static $WTSClientDirectory = 11 Global Static $WTSClientProductId = 12 Global Static $WTSClientHardwareId = 13 Global Static $WTSClientAddress = 14 Global Static $WTSClientDisplay = 15 Global Static $WTSClientProtocolType = 16 Global Static $WTSIdleTime = 17 Global Static $WTSLogonTime = 18 Global Static $WTSIncomingBytes = 19 Global Static $WTSOutgoingBytes = 20 Global Static $WTSIncomingFrames = 21 Global Static $WTSOutgoingFrames = 22 Global Static $WTSClientInfo = 23 Global Static $WTSSessionInfo = 24 Global Static $WTSSessionInfoEx = 25 Global Static $WTSConfigInfo = 26 Global Static $WTSValidationInfo = 27 Global Static $WTSSessionAddressV4 = 28 Global Static $WTSIsRemoteSession = 29 Global $sINIfile = @ScriptDir & "\redirect.ini" $iGuiW = 500 $iGuiH = 200 $hGUI = GUICreate("RDP Desktop Redirect", $iGuiW, $iGuiH) GUISetOnEvent($GUI_EVENT_CLOSE, "_ExitApp") GUICtrlCreateLabel("This will redirect your current session to Console." & @CRLF & "This desktop will remain active, but you will be disconnected.", 0, 13, $iGuiW, 40, $SS_CENTER) GUICtrlSetFont(-1, 10, 600) GUICtrlCreateLabel("Select the desktop Display Settings to use after the redirect", 0, 70, $iGuiW, 17, $SS_CENTER) $hDisplaySetting = GUICtrlCreateCombo("<Max>", 40, 90, 240, 20) ;This will be loaded from .ini if found $hBtnRedirect = GUICtrlCreateButton("Redirect and Disconnect", 40, $iGuiH - 50, 160, 25) GUICtrlSetOnEvent($hBtnRedirect, "_RedirectNow") GUICtrlCreateButton("Exit", $iGuiW - 140, $iGuiH - 50, 100, 25) GUICtrlSetOnEvent(-1, "_ExitApp") ;Disable the Redirect button if this is not an RDP session ; Create a red note next to redirect to say Not an RDP session. $sConnType = _WTSQuerySessionInformation($WTS_CURRENT_SESSION, $WTSClientProtocolType) ;What type of connection was used for this session 2 = RDP ConsoleWrite("$WTSClientProtocolType " & $sConnType & @CRLF) If $sConnType <> 2 Then ;2 = RDP connection GUICtrlCreateLabel("Not an RDP connection", 205, $iGuiH - 45, 140, 17) GUICtrlSetColor(-1, $COLOR_RED) GUICtrlSetState($hBtnRedirect, $GUI_DISABLE) EndIf ;Read the .ini if exists and populate the combobox $aDisplayOptions = IniReadSection($sINIfile, "Display") If @error Then GUICtrlCreateLabel("List available after the first redirect", 285, 93, $iGuiW - 285, 17) Else ;load the returned array into the combobox For $i = 1 to $aDisplayOptions[0][0] _GUICtrlComboBox_AddString($hDisplaySetting, $aDisplayOptions[$i][1]) Next EndIf GUISetState(@SW_SHOW, $hGUI) While 1 sleep(100) WEnd Func _RedirectNow() FileWriteLine($sLogFile, $sSeperator & @CRLF & " " & @MON & "/" & @MDAY & "/" & @YEAR & " " & @HOUR & ":" & @MIN & ":" & @SEC & "." & @MSEC) $id = _WTSQuerySessionInformation($WTS_CURRENT_SESSION, $WTSSessionId) ;Get the current users SessionId ConsoleWrite("My Session ID: " & $id & @CRLF) $Username = _WTSQuerySessionInformation($WTS_CURRENT_SESSION, $WTSUserName) ;Get the username for the specified session ConsoleWrite("My Username: " & $Username & @CRLF) $sConnFrom = _WTSQuerySessionInformation($WTS_CURRENT_SESSION, $WTSClientName) ;Where the connected user is from (computername) ConsoleWrite("Connected From " & $sConnFrom & @CRLF) If $sConnType = 2 Then ; 2 = RDP Local $aRes[4] ;Store the resolution details needed to update res after switching to console $sDisplaySelection = GUICtrlRead($hDisplaySetting) ;what did the user pick from the dropdown? ;ConsoleWrite("About to redirect to Console: " & @HOUR & ":" & @MIN & ":" & @SEC & "." & @MSEC & @CRLF) FileWriteLine($sLogFile, " RDP Session " & $id & " Redirect to console session 0 initiated by " & $Username & " from " & $sConnFrom) _RedirectToConsole($id) ;Redirect the logged in RDP session to the console to maintain an active desktop for automation While _WTSQuerySessionInformation($WTS_CURRENT_SESSION, $WTSClientProtocolType) = 2 ;Sleep until the Session type is no longer RDP sleep(200) WEnd Sleep(2000) ;Pull every available graphic option from the console and save to the .ini file for selection on the next run IniDelete($sINIfile, "Display", "") ;Delete any existing display settings $aAllOptions = _EnumDisplaySettingsEx() ;Retrieve array of all valid display settings For $i = 0 to UBound($aAllOptions) - 1 IniWrite($sINIfile, "Display", $i, $aAllOptions[$i][4]) Next FileWriteLine($sLogFile, " - " & UBound($aAllOptions) & " valid display settings were found for console. Saved to .ini for next run") ;If something besides <max> has been selected, then choose that If $sDisplaySelection = "<Max>" Then $aRes[0] = $aAllOptions[0][0] $aRes[1] = $aAllOptions[0][1] $aRes[2] = $aAllOptions[0][2] $aRes[3] = $aAllOptions[0][3] Else ;Find the selected display in the [][4] and use that FileWriteLine($sLogFile, " - " & $sDisplaySelection & " was specified instead of opting for <Max>") For $f = 0 to UBound($aAllOptions) - 1 If $aAllOptions[$f][4] = $sDisplaySelection Then $aRes[0] = $aAllOptions[$f][0] $aRes[1] = $aAllOptions[$f][1] $aRes[2] = $aAllOptions[$f][2] $aRes[3] = $aAllOptions[$f][3] ExitLoop EndIf Next EndIf If $aRes[0] = "" or $aRes[1] = "" or $aRes[2] = "" or $aRes[3] = "" Then FileWriteLine($sLogFile, " - Custom Resolution was not found in Console, Left at default: " & @DesktopWidth & "x" & @DesktopHeight & " at " & @DesktopDepth & "dpi with " & @DesktopRefresh & "Hz refresh rate") Exit EndIf _ChangeScreenResEx(1, $aRes[0], $aRes[1], $aRes[2], $aRes[3]) ;Set the display to the max value Sleep(2000) FileWriteLine($sLogFile, " - Screen resolution set to " & @DesktopWidth & "x" & @DesktopHeight & " at " & @DesktopDepth & "dpi with " & @DesktopRefresh & "Hz refresh rate") ;---------------------------------------------------------------------------------------------------------- ;This is where your automation code would go, take screenshots, interact with Desktop, etc... ;---------------------------------------------------------------------------------------------------------- Exit Else MsgBox(0, "Redirect - Disconnect", "This must be launched via a Remote Desktop Connection") EndIf Exit EndFunc Func _RedirectToConsole($iSessionID) _WinAPI_Wow64EnableWow64FsRedirection(True) ShellExecute(@WindowsDir & '\System32\tscon.exe', $iSessionID & ' /dest:console', '', 'runas') _WinAPI_Wow64EnableWow64FsRedirection(False) EndFunc ;Mod of argumentum code at https://www.autoitscript.com/forum/topic/134679-get-hostname-of-the-client-connected-to-the-terminalserver-session/ Func _WTSQuerySessionInformation($SessionId = -1, $WTSInfoClass = 10, $iReturnAsIs = 0) Local $aResult = DllCall("Wtsapi32.dll", "int", "WTSQuerySessionInformation", "Ptr", 0, "int", $SessionId, "int", $WTSInfoClass, "ptr*", 0, "dword*", 0) If @error Or $aResult[0] = 0 Then Return SetError(1, 0, "") Local $ip = DllStructGetData(DllStructCreate("byte[" & $aResult[5] & "]", $aResult[4]), 1) DllCall("Wtsapi32.dll", "int", "WTSFreeMemory", "ptr", $aResult[4]) If $iReturnAsIs Then Return $ip Switch $WTSInfoClass Case 4 ; We want the WTSSessionId Return Int('0x' & StringTrimRight(StringReverse($ip), 3)) Case 29 ; 1 = Its remote, 0 = physical connection $WTSIsRemoteSession Return Int('0x' & StringTrimRight(StringReverse($ip), 3)) case 16 ; $WTSClientProtocolType Return Int('0x' & StringTrimRight(StringReverse($ip), 3)) Case 14 ; We want the WTSClientAddress If Not (Int(StringLeft($ip, 4)) = 2) Then ; IPv4 $ip = "" Else $ip = Dec(StringMid($ip, 15, 2)) & '.' & Dec(StringMid($ip, 17, 2)) & '.' & Dec(StringMid($ip, 19, 2)) & '.' & Dec(StringMid($ip, 21, 2)) EndIf EndSwitch Return StringReplace(BinaryToString($ip), Chr(0), "") EndFunc ;==>_GetWTSClientName ;============================================================== ;=== Return array containing all valid display resolutions ;=== [#][0] = Width ;=== [#][1] = Height ;=== [#][2] = dpi ;=== [#][3] = Refresh Rate ;=== [#][4] = All values in a user readable string ;=== ;=== Sorted Largest to smallest, dups removed ;=== Origionally from rasim ;=== Modified by: BigDaddyO ;============================================================== Func _EnumDisplaySettingsEx() Local $DEVMODE, $DllRet = 0, $enum = 0 local $aAll[1000][5] ;Create a structure to hold all the items that are returned from the EnumDisplaySettinsEx call $DEVMODE = DllStructCreate("char dmDeviceName[32];ushort dmSpecVersion;ushort dmDriverVersion;short dmSize;" & _ "ushort dmDriverExtra;dword dmFields;short dmOrientation;short dmPaperSize;short dmPaperLength;" & _ "short dmPaperWidth;short dmScale;short dmCopies;short dmDefaultSource;short dmPrintQuality;" & _ "short dmColor;short dmDuplex;short dmYResolution;short dmTTOption;short dmCollate;" & _ "byte dmFormName[32];dword dmBitsPerPel;int dmPelsWidth;dword dmPelsHeight;" & _ "dword dmDisplayFlags;dword dmDisplayFrequency") DllStructSetData($DEVMODE, "dmSize", DllStructGetSize($DEVMODE)) $enum = 0 ;Used to track how many display settings have been added to the $aList Do $DllRet = DllCall("user32.dll", "int", "EnumDisplaySettingsEx", "ptr", 0, "dword", $enum, _ "ptr", DllStructGetPtr($DEVMODE), "dword", 0) $DllRet = $DllRet[0] ;Need to retrieve everything into a 2D array, Sort by the Width in Descending order. ; Then loop through writing them into a single string making sure there are no duplicates and returning as a 1D array $aAll[$enum][0] = Int(DllStructGetData($DEVMODE, "dmPelsWidth")) $aAll[$enum][1] = Int(DllStructGetData($DEVMODE, "dmPelsHeight")) $aAll[$enum][2] = Int(DllStructGetData($DEVMODE, "dmBitsPerPel")) $aAll[$enum][3] = Int(DllStructGetData($DEVMODE, "dmDisplayFrequency")) $aAll[$enum][4] = $aAll[$enum][0] & "x" & $aAll[$enum][1] & ", " & $aAll[$enum][2] & "dpi, " & $aAll[$enum][3] & "Hz" ConsoleWrite("Display Setting = " & $aAll[$enum][4] & @CRLF) $enum += 1 Until $DllRet = 0 $DEVMODE = 0 ;Clear out the DLL Struct before we leave the Func ReDim $aAll[$enum][5] ;Resize to the number of items we actually retrieved _ArraySort($aAll, 1) ;Sort the array so its in the order we want ;Move through the array to get rid of any dups Local $aList[$enum][5] ;This will hold the display settigns without any dups Local $iAdd = 0 ;Keep track of the number of unique records For $d = 0 to $enum - 1 ;Loop through every record returned For $f = 0 to $iAdd ;Loop through only those we already verified as not dups If $aList[$f][4] = $aAll[$d][4] Then ContinueLoop(2) ;We found it, so just skip to the next record EndIf Next ;We will only get to this part of the loop if we didn't find a dup $aList[$iAdd][0] = $aAll[$d][0] $aList[$iAdd][1] = $aAll[$d][1] $aList[$iAdd][2] = $aAll[$d][2] $aList[$iAdd][3] = $aAll[$d][3] $aList[$iAdd][4] = $aAll[$d][4] $iAdd += 1 Next ReDim $aList[$iAdd][5] Return $aList EndFunc ;=============================================================================== ; Function Name: _ChangeScreenResEx() ; Description: Changes the current screen geometry, colour and refresh rate. ; Version: 1.0.0.0 ; Parameter(s): $i_DisplayNum - Display to change, starting at 1 ; $i_Width - Width of the desktop screen in pixels. (horizontal resolution) ; $i_Height - Height of the desktop screen in pixels. (vertical resolution) ; $i_BitsPP - Depth of the desktop screen in bits per pixel. ; $i_RefreshRate - Refresh rate of the desktop screen in hertz. ; Return Value(s): On Success - Screen is adjusted, @ERROR = 0 ; On Failure - sets @ERROR = 1 ; Forum(s): ; Author(s): Original code - psandu.ro, PartyPooper ; Modifications - bobchernow ;=============================================================================== Func _ChangeScreenResEx($i_DisplayNum = 1, $i_Width = @DesktopWidth, $i_Height = @DesktopHeight, $i_BitsPP = @DesktopDepth, $i_RefreshRate = @DesktopRefresh) Local Const $DM_PELSWIDTH = 0x00080000 Local Const $DM_PELSHEIGHT = 0x00100000 Local Const $DM_BITSPERPEL = 0x00040000 Local Const $DM_DISPLAYFREQUENCY = 0x00400000 Local Const $CDS_TEST = 0x00000002 Local Const $CDS_UPDATEREGISTRY = 0x00000001 Local Const $DISP_CHANGE_RESTART = 1 Local Const $DISP_CHANGE_SUCCESSFUL = 0 Local Const $HWND_BROADCAST = 0xffff Local Const $WM_DISPLAYCHANGE = 0x007E If $i_Width = "" Or $i_Width = -1 Then $i_Width = @DesktopWidth; default to current setting If $i_Height = "" Or $i_Height = -1 Then $i_Height = @DesktopHeight; default to current setting If $i_BitsPP = "" Or $i_BitsPP = -1 Then $i_BitsPP = @DesktopDepth; default to current setting If $i_RefreshRate = "" Or $i_RefreshRate = -1 Then $i_RefreshRate = @DesktopRefresh; default to current setting Local $DEVMODE = DllStructCreate("byte[32];int[10];byte[32];int[6]") Local $s_Display $s_Display = "\\.\Display" & $i_DisplayNum Local $B = DllCall("user32.dll", "int", "EnumDisplaySettings", "ptr", 0, "int", 0, "ptr", DllStructGetPtr($DEVMODE)) If @error Then $B = 0 SetError(1) Return $B Else $B = $B[0] EndIf If $B <> 0 Then DllStructSetData($DEVMODE, 2, BitOR($DM_PELSWIDTH, $DM_PELSHEIGHT, $DM_BITSPERPEL, $DM_DISPLAYFREQUENCY), 5) DllStructSetData($DEVMODE, 4, $i_Width, 2) DllStructSetData($DEVMODE, 4, $i_Height, 3) DllStructSetData($DEVMODE, 4, $i_BitsPP, 1) DllStructSetData($DEVMODE, 4, $i_RefreshRate, 5) $B = DllCall("user32.dll", "int", "ChangeDisplaySettingsEx","str", $s_Display, "ptr", DllStructGetPtr($DEVMODE), "hwnd", 0, "dword", $CDS_TEST, "lparam", 0) If @error Then $B = -1 Else $B = $B[0] EndIf Select Case $B = $DISP_CHANGE_RESTART $DEVMODE = "" Return 2 Case $B = $DISP_CHANGE_SUCCESSFUL DllCall("user32.dll", "int", "ChangeDisplaySettingsEx","str", $s_Display, "ptr", DllStructGetPtr($DEVMODE), "hwnd", 0, "dword", $CDS_UPDATEREGISTRY, "lparam", 0) DllCall("user32.dll", "int", "SendMessage", "hwnd", $HWND_BROADCAST, "int", $WM_DISPLAYCHANGE, _ "int", $i_BitsPP, "int", $i_Height * 2 ^ 16 + $i_Width) $DEVMODE = "" Return 1 Case Else $DEVMODE = "" SetError(1) Return $B EndSelect EndIf EndFunc;==>_ChangeScreenResEx Func _ExitApp() Exit EndFunc1 point
-
1 point
-
1 point
-
CSV file editor
pixelsearch reacted to Musashi for a topic
Just as an information for people who may have some difficulties with the english language : I have published a thread in the german forum with a translation of the main instructions (in accordance with the author !). https://autoit.de/thread/86733-csv-file-editor/ The download link etc. remains of course in this main thread of @pixelsearch . To the moderators : I hope that it is allowed in this case.1 point -
CSV file editor
FrancescoDiMuro reacted to pixelsearch for a topic
Hi everybody New Version 901t (Jan 3, 2020) 3 functionalities added : Rename Header , Insert Column , Delete Column (right click on column header to display its context menu) Here is an example after we right click the "type" header (please note how >>> type <<< appears at 1st line in the context menu, so the user is 100% sure of the involved column) 2nd line "Export now ?" is recommended in case you gonna Sort or Delete this column (a warning will appear if you choose to delete) Microsoft made it a bit difficult to insert natively a column before column 0, as discussed here. If you really want to do this, just insert a column after column 0, then drag its header at the very left to switch both leftmost columns. Download link at the end of 1st post1 point -
How can i expand a line in csv file like...
TheXman reacted to FrancescoDiMuro for a topic
Hi @ratakantez, and welcome to the AutoIt forums Study the example script below, which is quite commented, and make questions if you need them. AutoIt is such a powerful language; all you need to know, is look at the Help file, try and study all the samples provided there and here on the Forums, and, if you feel the need, make questions here, always providing a script that can be ran, and explaining in details what you are trying to do. SampleFile.csv: Happy new year you too!1 point -
Thanks for your support Musashi! I appreciate it. Yeah, it certainly is difficult, especially like how you pointed out, any idiot can do a google search. It's good to know there are people willing to help keep the place clean Also I appreciate your input junkew. That is something I didnt think about. I'll have to think about it and come up with a solution. And thanks JLogan for merging the posts. I was confused where I should be posting them. I know that I'm no expert at autoit, but i figure if I can at least get people in the door, we can maybe improve the community. I'll work harder to make content that the community accepts. Happy new years everyone!1 point
-
Just install OpenSSL and you can do any automation with the stuff mentioned in the page you provide.1 point
-
Selecting from an array of buttons - (Moved)
markyrocks reacted to BGarr33434 for a topic
At the end of the day, at 50,000 ft in the air, I decided it was much easier to use a one dimensional array. I only needed to display on 2 axis . but I really do appreciate the education. Thanks and happy new year to all1 point -
Are my AutoIt exes really infected?
seadoggie01 reacted to JLogan3o13 for a topic
Did you really think, for as long as AutoIt has supported Windows 10 (on systems with Defender), that if this was the case it wouldn't have been advertised far and wide?? In the future, rather than making a definitive statement such as this and then having to come back and retract it, perhaps start by asking a question in the forum about the problems you're encountering.1 point -
$Enter_KEY = GUICtrlCreateDummy() Dim $Arr[1][2] = [["{ENTER}", $Enter_KEY]] GUISetAccelerators($Arr) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Enter_KEY if _OIG_IsFocused($h_GUI, $inp_ext) Then GUICtrlSetState($inp_taille,$GUI_FOCUS) ;~ if GUICtrlGetState($inp_ext)=80 Then ;~ GUICtrlSetState($inp_taille,$GUI_FOCUS) EndIf EndSwitch WEnd Func _OIG_IsFocused($h_Wnd, $i_ControlID) ; Check if a control has focus. Return ControlGetHandle($h_Wnd, '', $i_ControlID) = ControlGetHandle($h_Wnd, '', ControlGetFocus($h_Wnd)) EndFunc ;==>_OIG_IsFocused Untested. $h_GUI should be the handle to your GUI1 point
-
A little late but the solution is simple. Just remove the modeless style of the context menu. Include GuiMenu.au3 in the code in the first post and replace this line: Local $contextmenu = GUICtrlCreateContextMenu() with these three lines: Local $contextmenu = GUICtrlCreateContextMenu() Local $hCM = GUICtrlGetHandle( $contextmenu ) _GUICtrlMenu_SetMenuStyle($hCM, BitXOR(_GUICtrlMenu_GetMenuStyle($hCM), $MNS_MODELESS)) The A's will keep printing when you activate the context menu.1 point
-
Trapping $NM_RETURN in a ListView via WM_NOTIFY
matwachich reacted to Yashied for a topic
In order to use the return key in ListView, you must replace its default WindowProc procedure as follows. Func _WindowProc($hWnd, $iMsg, $wParam, $lParam) Switch $iMsg Case $WM_GETDLGCODE Switch $wParam Case $VK_RETURN Return $DLGC_WANTALLKEYS EndSwitch EndSwitch Return _WinAPI_CallWindowProc($pDefWindowProc, $hWnd, $iMsg, $wParam, $lParam) EndFunc ;==>_WindowProc But unfortunately DllCallbackRegister() will not work properly here. But you can write your own DLL. Global Comctl32.l = OpenLibrary(#PB_Any, "comctl32.dll") ProcedureDLL.i SubclassProc(*HWnd, Msg.l, *WParam, *LParam, *ID, *IParam) Select Msg Case #WM_GETDLGCODE Select *WParam Case #VK_RETURN ProcedureReturn #DLGC_WANTALLKEYS EndSelect EndSelect ProcedureReturn CallFunction(Comctl32, "DefSubclassProc", *HWnd, Msg, *WParam, *LParam) EndProcedure WSP.dll And a simple example. #Include <APIConstants.au3> #Include <GUIListView.au3> #Include <GUIConstantsEx.au3> #Include <ListViewConstants.au3> #Include <WinAPIEx.au3> OnAutoItExitRegister('AutoItExit') $hForm = GUICreate('MyGUI', 300, 300) $hLV = GUICtrlGetHandle(GUICtrlCreateListView('Name', 0, 0, 300, 300, -1, 0)) For $i = 1 To 4 _GUICtrlListView_AddItem($hLV, 'Item' & $i) Next $hDll = _WinAPI_LoadLibrary(@ScriptDir & 'WSP.dll') If $hDll Then $pSubclassProc = _WinAPI_GetProcAddress($hDll, 'SubclassProc') If Not @error Then _WinAPI_SetWindowSubclass($hLV, $pSubclassProc, 1000) Else _WinAPI_FreeLibrary($hDll) EndIf EndIf $Dummy = GUIctrlCreateDummy() GUIRegisterMsg($WM_NOTIFY, 'WM_NOTIFY') GUISetState() While 1 Switch GUIGetMsg() Case 0 ContinueLoop Case $GUI_EVENT_CLOSE Exit Case $Dummy MsgBox(0, '', _GUICtrlListView_GetItemText($hLV, GUICtrlRead($Dummy)) & ' is activated.') EndSwitch WEnd Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) Local $tNMIA = DllStructCreate($tagNMITEMACTIVATE, $lParam) Local $hTarget = DllStructGetData($tNMIA, 'hWndFrom') Local $ID = DllStructGetData($tNMIA, 'Code') Switch $hTarget Case $hLV Switch $ID Case $LVN_ITEMACTIVATE Local $Item = DllStructGetData($tNMIA, 'Index') If _GUICtrlListView_GetItemSelected($hLV, $Item) Then GUICtrlSendToDummy($Dummy, $Item) EndIf EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY Func AutoItExit() If $pSubclassProc Then _WinAPI_RemoveWindowSubclass($hLV, $pSubclassProc, 1000) EndIf EndFunc ;==>AutoItExit @Melba23 Yes it works, but it has several drawbacks: _GUICtrlListView_GetSelectedIndices() may be too slow for a large number of items.You should check the current focus.0 points