Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 02/25/2016 in all areas

  1. #include <MsgBoxConstants.au3> Global Const $JOHN_ONE = "JohnOne" Global Const $CRAP = "Magic Numbers" Msgbox($MB_ICONWARNING, $JOHN_ONE, "Really, you used too much " & $CRAP)
    2 points
  2. lol forgot about getcursorinfo and just wrote this mess... Opt("MouseCoordMode", 2) Local $iLeft = 10, $iTop = 10, $iWidth = 185, $iHeight = 20 Example() Func Example() Local $hGUI ; Create GUI $hGUI = GUICreate("(UDF) ComboBox Create", 400, 296) Local $idComboBox = GUICtrlCreateCombo("Item 1", $iLeft, $iTop, $iWidth, $iHeight) GUICtrlSetData($idComboBox, "Item 2|Item 3", "Item 2") $g_hCombo = GUICtrlGetHandle($idComboBox) GUISetState(@SW_SHOW) Local $msg = 0 Do $msg = GUIGetMsg() If $msg = 0 Then ContinueLoop If $msg = -7 Then _PrimaryClick() EndIf Until $msg = -3 GUIDelete() EndFunc ;==>Example Func _PrimaryClick() $ix = MouseGetPos(0) $iy = MouseGetPos(1) ConsoleWrite($ix & @LF) ConsoleWrite($iy & @LF) If ($ix > $iLeft) And ($ix < ($iLeft + $iWidth)) Then If $iy > $iTop And $iy < $iTop + $iHeight Then ConsoleWrite("Clicked" & @LF) EndIf EndIf EndFunc ;==>_PrimaryClick
    1 point
  3. Then the only way is to use a workaround But as GuiGetMsg allows detection of 90%+ of the usual control events it should not be a great trouble #include <GUIConstantsEx.au3> $hGUI = GUICreate("Combo", 400, 296) Local $idComboBox = GUICtrlCreateCombo("Item 1", 10, 10, 185, 20) GUICtrlSetData($idComboBox, "Item 2|Item 3", "Item 2") GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $GUI_EVENT_PRIMARYDOWN $a = GUIGetCursorInfo() If $a[4] = $idComboBox Then ConsoleWrite("combo just clicked" & @crlf) Case $idComboBox ConsoleWrite("combo item selected" & @crlf) EndSwitch WEnd
    1 point
  4. kcvinu, And hence the introduction of GUIRegisterMsg which allows the more experienced coder to access virtually all of the messages associated with a control. But you definitely need to know what you are doing when you get to that level, so it is probably best that the newer coders are somewhat sheltered. M23
    1 point
  5. kcvinu, That is a question that only Jon could answer, but I would hazard a guess that it is based on keeping the code simple for the less-experienced AutoIt user. Being able to use a simple ControlID in a loop to detect the most common events occurring to a control rather than having to create relatively complicated event handlers for every case would seem a pretty sensible design decision. M23
    1 point
  6. Yes, because this is not for google.com
    1 point
  7. If you can avoid using Send, do so #include <WinAPISys.au3> If (Not Ping("192.168.0.13")) Then _WinAPI_LockWorkStation() If ping does not respond, Lock Workstation.
    1 point
  8. @DoomSack please read How to post code on the forum Here is example how you can try to solve your problem: #include <IE.au3> _Example() Func _Example() Local $oIE = _IEAttach(.....) Local $oIE_DIV = _IEGetObjById($oIE,'stream-item-user-3099023815') ; first approach Local $oIE_ObjectToClick1 = $oIE_DIV.nextElementSibling.nextElementSibling _IEAction($oIE_ObjectToClick1,'click') ; second approach Local $oIE_ObjectToClick2 = $oIE_DIV.nextSibling.nextSibling _IEAction($oIE_ObjectToClick2,'click') EndFunc Some reference documentation: https://msdn.microsoft.com/en-us/library/ms535240(v=vs.85).aspx https://msdn.microsoft.com/en-us/library/ff974796(v=vs.85).aspx https://msdn.microsoft.com/en-us/library/ms534189(v=vs.85).aspx btw. Welcome to the forum.
    1 point
  9. fixitrod, Interesting - I was pleasantly surprised that it took so little! M23
    1 point
  10. fixitrod, A fun little problem - this approach seems to work nicely: #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> HotKeySet("{SPACE}", "_Follow") HotKeySet("{ESC}", "_Exit") $hGUI = GUICreate("Test", 500, 500) $cGraphic = GUICtrlCreateGraphic(0, 0, 500, 500) GUICtrlSetGraphic($cGraphic, $GUI_GR_ELLIPSE, 50, 50, 400, 400) GUICtrlSetGraphic($cGraphic, $GUI_GR_RECT, 150, 150, 200, 200) GUICtrlSetGraphic($cGraphic, $GUI_GR_PIE, 200, 300, 100, 30, 70) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func _Follow() ; Array holding next position to check for each direction [delta-X, Delta-Y] Local $aDirn[8][2] = [[0, -1], _ [1, -1], _ [1, 0], _ [1, 1], _ [0, 1], _ [-1, 1], _ [-1, 0], _ [-1, -1]] ; Array to hold search directions relative to current direction Local $aSearch[] = [0, 1, -1, 2, -2, 3, -3] ; See if on line $aStartPos = MouseGetPos() $iStart_X = $aStartPos[0] $iStart_Y = $aStartPos[1] If PixelGetColor($iStart_X, $iStart_Y) = 0x000000 Then ; Set start position $iCurr_X = $iStart_X $iCurr_Y = $iStart_Y Else ConsoleWrite("Searching for line" & @CRLF) ; Search for initial point in immediately surrounding pixels For $iFindDirn = 0 To UBound($aSearch) - 1 $iFind_X = $iStart_X + $aDirn[$iFindDirn][0] $iFind_Y = $iStart_Y + $aDirn[$iFindDirn][1] If PixelGetColor($iFind_X, $iFind_Y) = 0x000000 Then ExitLoop EndIf Next ; Check if found If $iFindDirn > UBound($aSearch) - 1 Then ConsoleWrite("Cannot find line!" & @CRLF & @CRLF) Return EndIf ; Set start position $iCurr_X = $iFind_X $iCurr_Y = $iFind_Y $iStart_X = $iFind_X $iStart_Y = $iFind_Y EndIf ConsoleWrite("Ready to go!" & @CRLF) ; Check for possible directions $iCurrDirn = -1 For $iDirnCheck = 0 To 7 ; Search around for another pixel $iFirstMove_X = $iCurr_X + $aDirn[$iDirnCheck][0] $iFirstMove_Y = $iCurr_Y + $aDirn[$iDirnCheck][1] If PixelGetColor($iFirstMove_X, $iFirstMove_Y) = 0x000000 Then ; Set direction $iCurrDirn = $iDirnCheck ExitLoop EndIf Next ; Check direction is set If $iCurrDirn = -1 Then ConsoleWrite("Cannot follow!" & @CRLF & @CRLF) Return EndIf While 1 ; Check likely directions for pixel For $iDirnChange = 0 To UBound($aSearch) - 1 ; Determine direction to check $iCheckDirn = $iCurrDirn + $aSearch[$iDirnChange] If $iCheckDirn < 0 Then $iCheckDirn = $iCheckDirn + 8 ElseIf $iCheckDirn > 7 Then $iCheckDirn = $iCheckDirn - 8 EndIf ; Prevent backtracking If Abs($iCurrDirn - $iCheckDirn) = 4 Then ContinueLoop ; Look for pixel in that direction $iCheck_X = $iCurr_X + $aDirn[$iCheckDirn][0] $iCheck_Y = $iCurr_Y + $aDirn[$iCheckDirn][1] If PixelGetColor($iCheck_X, $iCheck_Y) = 0x000000 Then ; Move to this pixel ExitLoop EndIf Next If $iDirnChange > UBound($aSearch) - 1 Then ConsoleWrite("Lost it!" & @CRLF & @CRLF) Else ; Check if back to start If $iCheck_X = $iStart_X And $iCheck_Y = $iStart_Y Then ConsoleWrite("Back to the beginning!" & @CRLF & @CRLF) ExitLoop Else ; Set new coords $iCurr_X = $iCheck_X $iCurr_Y = $iCheck_Y ; Set new direction $iCurrDirn = $iCheckDirn ; Move mouse MouseMove($iCurr_X, $iCurr_Y) Sleep(10) EndIf EndIf WEnd EndFunc Func _Exit() Exit EndFunc You need to get the cursor with 1 pixel of the line and then press {SPACE} - any further away than that and the script sulks and announces that it cannot find the line. The "follow" algorithm will easily cope with right-angle turns (as you can see with the square) but will not follow anything tighter than that as it would seriously risk doubling back and can usually cope with more acute angles (as you can see with the triangle) - although that depends on exactly how the angle is drawn at the pixel level. Any use? if not then please post a file showing the actual lines you want to follow so I can try to tweak the code. M23 Edit: Now copes with more than 90 degree angles (most of the time!)
    1 point
  11. Anomalous, As I pointed out above, MS state quite clearly that "real" combos do not have the functionality to expand tabs, so something like this is probably as good as you will get. By all means modify the example code as much as you wish - anything I post here is free to use. M23
    1 point
  12. Drive the update to the edit control only when required... #Include <GUIConstants.au3> #Include <EditConstants.au3> #Include <WindowsConstants.au3> ; disallow some special chars and lower/upper case 'a' local $DisallowedCharsTable = '(?i)[\!\@\#\$\%\^\&\*\(\)A]' ; precede special chars with a '\' just for safety (some are required, some not) GUICreate('Character Filter Example', 300, 200) $Input = GUICtrlCreateInput('', 10, 10, 280, 19) GUIRegisterMsg($WM_COMMAND, 'WM_COMMAND') GUISetState() Do Until GUIGetMsg() = $GUI_EVENT_CLOSE Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam) Switch BitAND($wParam, 0xFFFF) Case $Input Switch BitShift($wParam, 16) Case $EN_UPDATE guictrlsetdata($Input,stringregexpreplace(guictrlread($Input),$DisallowedCharsTable,'')) EndSwitch EndSwitch Return $GUI_RUNDEFMSG endfunc kylomas edit:something is goofing my tabs up...
    1 point
×
×
  • Create New...