Leaderboard
Popular Content
Showing content with the highest reputation on 04/05/2023 in all areas
-
Keypress simulation with WinAPI functions directly
Dsmoeg999 and one other reacted to mistersquirrle for a topic
Awesome, I had tried messing around with padding and alignment of structs, but I'm not very good with DllStructs and that type of thing. So I never got it working, but I had tried some similar methods. Thank you for that example, for sure! This tells AutoIt if it should run your script under x86 (32-bit) or x64 (64-bit). By default when you install AutoIt it uses x86, though while installing you can change the default runtype to x64. So it sounds like that you've installed AutoIt to use x64 by default, and to get the script running as x86/32-bit, that "wrapper" line is needed. It just tells AutoIt to run as x86 (n) or x64 (y).2 points -
Keypress simulation with WinAPI functions directly
argumentum and one other reacted to TheXman for a topic
The example below works in 32 bit and 64 bit environments. INPUT is a struct that contains a union. Since the original post only asked about keyboard input, I did not include what the MOUSEINPUT and HARDWAREINPUT unions would look like. There are alignment issues that have to be taken into account when running 32 bit or 64 bit. The example shows one way of handling it. #AutoIt3Wrapper_AU3Check_Parameters=-w 3 -w 4 -w 5 -w 6 -d ;~ #AutoIt3Wrapper_UseX64=N #include <Constants.au3> #include <Array.au3> #include <WinAPIDiag.au3> Enum Step *2 _ $KEYEVENTF_EXTENDEDKEY = 1, _ $KEYEVENTF_KEYUP, _ $KEYEVENTF_UNICODE, _ $KEYEVENTF_SCANCODE Const $INPUT_KEYBOARD = 1 Const $VK_SHIFT = 0x10 Const $VK_A = 0x41 Const $tagKeyInput = _ "dword type;" & _ (@AutoItX64 ? "byte alignment_pad[4];" : "") & _ "struct;" & _ " word wVk;" & _ " word wScan;" & _ " dword dwFlags;" & _ " dword time;" & _ " ulong_ptr dwExtraInfo;" & _ " byte reserved[8];" & _ "endstruct;" example() Func example() #cs ========================================================= Using the SendInput win32 API, this example sends "AbC" to the last active notepad instance (if it exists). Note: "A" is sent by using virtual key code and "C" is sent using a scan code. It was done just to show the 2 different ways of sending keyboard input. #ce ========================================================= Local $tKeyInput, _ $tInputArray Local $aResult Local $iNumberOfInputs = 8 ;Create a struct to get size $tKeyInput = DllStructCreate($tagKeyInput) ;Create an inputs array buffer $tInputArray = DllStructCreate(StringFormat("byte bytes[%i];", DllStructGetSize($tKeyInput) * $iNumberOfInputs)) ;Load input array[0] $tKeyInput = DllStructCreate($tagKeyInput, DllStructGetPtr($tInputArray) + (0 * DllStructGetSize($tKeyInput))) $tKeyInput.type = $INPUT_KEYBOARD $tKeyInput.wVk = $VK_SHIFT ;Load input array[1] $tKeyInput = DllStructCreate($tagKeyInput, DllStructGetPtr($tInputArray) + (1 * DllStructGetSize($tKeyInput))) $tKeyInput.type = $INPUT_KEYBOARD $tKeyInput.wVk = $VK_A ;Load input array[2] $tKeyInput = DllStructCreate($tagKeyInput, DllStructGetPtr($tInputArray) + (2 * DllStructGetSize($tKeyInput))) $tKeyInput.type = $INPUT_KEYBOARD $tKeyInput.wvk = $VK_A $tKeyInput.dwFlags = $KEYEVENTF_KEYUP ;Load input array[3] $tKeyInput = DllStructCreate($tagKeyInput, DllStructGetPtr($tInputArray) + (3 * DllStructGetSize($tKeyInput))) $tKeyInput.type = $INPUT_KEYBOARD $tKeyInput.wVk = $VK_SHIFT $tKeyInput.dwFlags = $KEYEVENTF_KEYUP ;Load input array[4] $tKeyInput = DllStructCreate($tagKeyInput, DllStructGetPtr($tInputArray) + (4 * DllStructGetSize($tKeyInput))) $tKeyInput.type = $INPUT_KEYBOARD $tKeyInput.wScan = AscW("b") $tKeyInput.dwFlags = $KEYEVENTF_UNICODE ;Load input array[5] $tKeyInput = DllStructCreate($tagKeyInput, DllStructGetPtr($tInputArray) + (5 * DllStructGetSize($tKeyInput))) $tKeyInput.type = $INPUT_KEYBOARD $tKeyInput.wScan = AscW("b") $tKeyInput.dwFlags = $KEYEVENTF_UNICODE + $KEYEVENTF_KEYUP ;Load input array[6] $tKeyInput = DllStructCreate($tagKeyInput, DllStructGetPtr($tInputArray) + (6 * DllStructGetSize($tKeyInput))) $tKeyInput.type = $INPUT_KEYBOARD $tKeyInput.wScan = AscW("C") $tKeyInput.dwFlags = $KEYEVENTF_UNICODE ;Load input array[7] $tKeyInput = DllStructCreate($tagKeyInput, DllStructGetPtr($tInputArray) + (7 * DllStructGetSize($tKeyInput))) $tKeyInput.type = $INPUT_KEYBOARD $tKeyInput.wScan = AscW("C") $tKeyInput.dwFlags = $KEYEVENTF_UNICODE + $KEYEVENTF_KEYUP ;Activate notepad window If Not WinActivate("[CLASS:Notepad]") Then Exit MsgBox($MB_ICONERROR, "WinActivate Error", "Notepad window not found.") ;Send input $aResult = DllCall('user32.dll', 'uint', 'SendInput', _ 'uint' , $iNumberOfInputs, _ 'struct*', $tInputArray, _ 'int' , DllStructGetSize($tKeyInput)) If $aResult[0] = 0 Then MsgBox(0, "GetLastError", _WinAPI_GetLastErrorMessage()) EndFunc2 points -
Thank you @mistersquirrle simply removing @WindowsDir and specifying the sound path works fine.1 point
-
Play a sound file with SoundPlay Does not work.
Dsmoeg999 reacted to mistersquirrle for a topic
Why are you using @WindowsDir? Keep in mind that that's a macro used to point to your Windows folder, so for me it's: C:\WINDOWS This means your paths are: C:\WINDOWS\media\tada.wav C:\WINDOWSD:\MyFolder\Example\sound.wav That first one should be correct, but the second one definitely isn't. Does "D:\MyFolder\Example\sound.wav" work without @WindowsDir? Also, you may have whatever process is playing the sound muted in your Volume Mixer. I would try playing the sound in a loop and look at the volume mixer for what's the playing the sound and make sure it's not muted. The SoundPlay example for tada.wav worked for me.1 point -
Keypress simulation with WinAPI functions directly
Dsmoeg999 reacted to mistersquirrle for a topic
I also tried some things with SendInput, and in the end I decided that it wasn't worth it, as I'm pretty sure that AutoIt's Send uses it (though I haven't confirmed, so if someone with more knowledge wants to correct me...). The main problem, and likely that problem that you're having is that SendInput doesn't work (with what you have here) in x64 mode. Your code works for me if you make sure it's running as x86 by putting this at the top of your script: #AutoIt3Wrapper_UseX64=n I messed around with SendInput for a while trying to get it work with 64-bit but couldn't. I got it to the point where DllCall did not return any errors, so it seemed like it and SendInput were happy with everything, but nothing happened. Maybe someone knows how to get SendInput working with 64-bit, but it wasn't worth it to me. Also, keep in mind that with your SendInput call, you're not sending the key back UP, it's only being pressed down. You should send the key back up as well: Global Const $KEYEVENTF_KEYUP = 0x0002 And from the Microsoft page on SendInput: This function is subject to UIPI [User Interface Privilege Isolation]. Applications are permitted to inject input only into applications that are at an equal or lesser integrity level Meaning you may want/need to add #RequireAdmin to your script as well.1 point -
1 point
-
You could also implement the ability to calculate future dates, and also add another parameter to be able to indicate non-working days as you like (e.g. if someone works only Monday, Friday and Sunday he could pass '3,4,5,7' as holidays (assuming 1=Sunday, 2 =Monday , 3=Tuesday, 4=Wednesday, 5=Thursday, 6=Friday, 7=Saturday) For fun, I wrote a function that has these possibilities using SQL (sqlite), but in order not to hijack your topic, for those interested, I post it in the session dedicated to SQL at this link: https://www.autoitscript.com/forum/topic/210024-a-workday-function-using-sqlite/1 point
-
1 file would exceed the total allowed size
pixelsearch reacted to rudi for a topic
1 point -
MISSION ACCOMPLISHED! Except for the SQL stuff I took out, this has now reached awesome! Enjoy! #include <GUIConstantsEx.au3> #include <Array.au3> #Include <GuiListBox.au3> #include <WindowsConstants.au3> #include <EditConstants.au3> #include <ComboConstants.au3> Global $hGUI Global $hInput Global $hList Global $sPartialData Global $output = '' Local $conn = ObjCreate( "ADODB.Connection" ) Local $DSN = "DRIVER={SQL Server};SERVER=MyServer;DATABASE=MyDB;uid=MyUID;pwd=MyPaSsWoRd;" SQLQuery() $hGUI = GUICreate("Example", 200, 400) $hInput = GUICtrlCreateInput("", 5, 5, 190, 20) $hList = GUICtrlCreateList("", 5, 30, 190, 225, BitOR(0x00100000, 0x00200000)) GUICtrlSetLimit(-1, 20) GUICtrlSetState($hList, $GUI_Hide) $hButton = GUICtrlCreateButton("Read", 60, 360, 80, 30) $hUP = GUICtrlCreateDummy() $hDOWN = GUICtrlCreateDummy() $hENTER = GUICtrlCreateDummy() GUISetState(@SW_SHOW, $hGUI) Dim $AccelKeys[3][2]=[["{UP}", $hUP], ["{DOWN}", $hDOWN], ["{ENTER}", $hENTER]] GUISetAccelerators($AccelKeys) $sCurr_Input = "" $iCurrIndex = -1 GUIRegisterMsg($WM_COMMAND, "WM_COMMAND") While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $hList $sChosen = GUICtrlRead($hList) If $sChosen <> "" Then GUICtrlSetData($hInput, $sChosen) GUICtrlSetState($hList, $GUI_Hide) endif Case $hButton If $sPartialData <> "" Then $sFinal = GUICtrlRead($hInput) If _ArraySearch($MyVal, $sFinal) > 0 Then MsgBox(0, "Chosen", $sFinal) EndIf EndIf Case $hUP If $sPartialData <> "" Then $iCurrIndex -= 1 If $iCurrIndex < 0 Then $iCurrIndex = 0 _GUICtrlListBox_SetCurSel($hList, $iCurrIndex) EndIf Case $hDOWN If $sPartialData <> "" Then $iTotal = _GUICtrlListBox_GetCount($hList) $iCurrIndex += 1 If $iCurrIndex > $iTotal - 1 Then $iCurrIndex = $iTotal - 1 _GUICtrlListBox_SetCurSel($hList, $iCurrIndex) EndIf Case $hENTER If $iCurrIndex <> -1 Then $sText = _GUICtrlListBox_GetText($hList, $iCurrIndex) GUICtrlSetData($hInput, $sText) GUICtrlSetState($hList, $GUI_Hide) $iCurrIndex = -1 _GUICtrlListBox_SetCurSel($hList, $iCurrIndex) EndIf EndSwitch If GUICtrlRead($hInput) <> $sCurr_Input Then CheckInputText() $sCurr_Input = GUICtrlRead($hInput) EndIf WEnd Func CheckInputText() $sPartialData = "|" Local $sInput = GUICtrlRead($hInput) If $sInput <> "" Then For $i = 0 To Ubound($MyVal) - 1 If StringInStr($MyVal[$i], $sInput) <> 0 Then $sPartialData &= $MyVal[$i] & "|" Next GUICtrlSetData($hList, $sPartialData) EndIf EndFunc ;==>CheckInputText Func WM_COMMAND($hWnd, $msg, $wParam, $lParam) $nNotifyCode = BitShift($wParam, 16) $nID = BitAND($wParam, 0x0000FFFF) If $nID = $hInput Then $hCtrl = $lParam If $nNotifyCode = $EN_CHANGE Then $txt = GUICtrlRead($hInput) For $n = 1 To UBound($MyVal) - 1 ;Msgbox(0,"Records found: " & $n, $MyVal[$n]) If StringCompare(StringLeft($MyVal[$n], StringLen($txt)), $txt) = 0 Then GUICtrlSetData($hList, $MyVal[$n]) if GUICtrlRead($hInput) then GUICtrlSetState($hList, $GUI_show) else GUICtrlSetState($hList, $GUI_Hide) endif ExitLoop EndIf Next EndIf EndIf Return $GUI_RUNDEFMSG EndFunc ;==>WM_COMMAND Func SQLQuery() $conn.Open($DSN) $rs = ObjCreate( "ADODB.RecordSet" ) $rs.Open( "@@ PUT QUERY HERE @@", $conn ) If $RS.RecordCount Then While Not $RS.EOF $output = $output & StringStripWS($RS.Fields("@@ PUT TABLE HERE @@").Value,8) & "|" ; value of 4 columns on this line $RS.MoveNext WEnd EndIf global $MyVal = StringSplit($output,"|") $conn.close $sData = $output GUICtrlSetData($hList, $sData) $iCurrIndex = -1 _GUICtrlListBox_SetCurSel($hList, $iCurrIndex) EndFunc Thank you everyone of the help! And if anyone is dealing with SQL issues and searches, go ahead and use this. Dont forget to put the query and table at the bottom replacing the @@ signs1 point
-
Hi guys thanks for your contribution both examples work. @mistersquirrle indeed you are right Send does make a call to SendInput. I also get it to work by setting #AutoIt3Wrapper_UseX64=n I don't quite understand what the wrapper is for. Thank you both for the examples and solutions I will try to understand them better.0 points