Jump to content

Set Random Keystrokes at inputbox


Recommended Posts

  • Moderators

mar3011,

Can you explain more clearly what it is you are trying to do as that makes no sense to me at all.

What inputbox? Why do both "functions" start Notepad? Help us to help you by giving us more information.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to post
Share on other sites
  • Moderators

mar3011,

You have already said that - but it is no clearer a second time. I am out of here.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to post
Share on other sites

i want something like this but for open notepad while you set keys to inputbox then you press on keyboard key that you selected

#include <GUIConstantsEx.au3>
#include <WinAPI.au3>
#Include <WindowsConstants.au3>

;HotKeySet('{CAPSLOCK}', '_ExcludeHotkey')
;HotKeySEt('{NUMLOCK}', '_ExcludeHotkey')

Global Const $HKM_SETHOTKEY = $WM_USER + 1
Global Const $HKM_GETHOTKEY = $WM_USER + 2
Global Const $HKM_SETRULES = $WM_USER + 3

Global Const $HOTKEYF_ALT = 0x04
Global Const $HOTKEYF_CONTROL = 0x02
Global Const $HOTKEYF_EXT = 0x80; Extended key
Global Const $HOTKEYF_SHIFT = 0x01

; invalid key combinations
Global Const $HKCOMB_A = 0x8; ALT
Global Const $HKCOMB_C = 0x4; CTRL
Global Const $HKCOMB_CA = 0x40; CTRL+ALT
Global Const $HKCOMB_NONE = 0x1; Unmodified keys
Global Const $HKCOMB_S = 0x2; SHIFT
Global Const $HKCOMB_SA = 0x20; SHIFT+ALT
Global Const $HKCOMB_SC = 0x10; SHIFT+CTRL
Global Const $HKCOMB_SCA = 0x80; SHIFT+CTRL+ALT


Global $HotkeyMap
Dim $HotkeyMap[67][2]
$HotkeyMap[0][0] = "{CAPSLOCK}"
$HotkeyMap[0][1] = 20
$HotkeyMap[1][0] = "{NUMPAD0}"
$HotkeyMap[1][1] = 96
$HotkeyMap[2][0] = "{NUMPAD1}"
$HotkeyMap[2][1] = 97
$HotkeyMap[3][0] = "{NUMPAD2}"
$HotkeyMap[3][1] = 98
$HotkeyMap[4][0] = "{NUMPAD3}"
$HotkeyMap[4][1] = 99
$HotkeyMap[5][0] = "{NUMPAD4}"
$HotkeyMap[5][1] = 100
$HotkeyMap[6][0] = "{NUMPAD6}"
$HotkeyMap[6][1] = 101
$HotkeyMap[7][0] = "{NUMPAD7}"
$HotkeyMap[7][1] = 102
$HotkeyMap[8][0] = "{NUMPAD8}"
$HotkeyMap[8][1] = 103
$HotkeyMap[9][0] = "{NUMPAD8}"
$HotkeyMap[9][1] = 104
$HotkeyMap[10][0] = "{NUMPAD9}"
$HotkeyMap[10][1] = 105
$HotkeyMap[11][0] = "{NUMPADMULT}"
$HotkeyMap[11][1] = 106
$HotkeyMap[12][0] = "{NUMPADADD}"
$HotkeyMap[12][1] = 107
$HotkeyMap[13][0] = "{NUMPADSUB}"
$HotkeyMap[13][1] = 109
$HotkeyMap[14][0] = "{NUMPADDOT}"
$HotkeyMap[14][1] = 110
$HotkeyMap[15][0] = "{NUMPADDIV}"
$HotkeyMap[15][1] = 111
$HotkeyMap[16][0] = "{F1}"
$HotkeyMap[16][1] = 112
$HotkeyMap[17][0] = "{F2}"
$HotkeyMap[17][1] = 113
$HotkeyMap[18][0] = "{F3}"
$HotkeyMap[18][1] = 114
$HotkeyMap[19][0] = "{F4}"
$HotkeyMap[19][1] = 115
$HotkeyMap[20][0] = "{F5}"
$HotkeyMap[20][1] = 116
$HotkeyMap[21][0] = "{F6}"
$HotkeyMap[21][1] = 117
$HotkeyMap[22][0] = "{F7}"
$HotkeyMap[22][1] = 118
$HotkeyMap[23][0] = "{F8}"
$HotkeyMap[23][1] = 119
$HotkeyMap[24][0] = "{F9}"
$HotkeyMap[24][1] = 120
$HotkeyMap[25][0] = "{F10}"
$HotkeyMap[25][1] = 121
$HotkeyMap[26][0] = "{F11}"
$HotkeyMap[26][1] = 122
$HotkeyMap[27][0] = "{F12}"
$HotkeyMap[27][1] = 123
$HotkeyMap[28][0] = "{SCROLLLOCK}"
$HotkeyMap[28][1] = 145

;even though the buttons below don't have AU3 tags, they have different ASCII code
$HotkeyMap[29][0] = ";"
$HotkeyMap[29][1] = 186
$HotkeyMap[30][0] = "="
$HotkeyMap[30][1] = 187
$HotkeyMap[31][0] = "-"
$HotkeyMap[31][1] = 189
$HotkeyMap[32][0] = "."
$HotkeyMap[32][1] = 190
$HotkeyMap[33][0] = "/"
$HotkeyMap[33][1] = 191
$HotkeyMap[34][0] = "`"
$HotkeyMap[34][1] = 192
$HotkeyMap[35][0] = "["
$HotkeyMap[35][1] = 219
$HotkeyMap[36][0] = "\"
$HotkeyMap[36][1] = 220
$HotkeyMap[37][0] = "]"
$HotkeyMap[37][1] = 221
$HotkeyMap[38][0] = "'"
$HotkeyMap[38][1] = 222

$HotkeyMap[39][0] = "{HOME}"
$HotkeyMap[39][1] = 2084
$HotkeyMap[40][0] = "{END}"
$HotkeyMap[40][1] = 2083
$HotkeyMap[41][0] = "{INSERT}"
$HotkeyMap[41][1] = 2093
$HotkeyMap[42][0] = "{PGUP}"
$HotkeyMap[42][1] = 2081
$HotkeyMap[43][0] = "{PGDN}"
$HotkeyMap[43][1] = 2082
$HotkeyMap[44][0] = "{LEFT}"
$HotkeyMap[44][1] = 2085
$HotkeyMap[45][0] = "{RIGHT}"
$HotkeyMap[45][1] = 2087
$HotkeyMap[46][0] = "{UP}"
$HotkeyMap[46][1] = 2086
$HotkeyMap[47][0] = "{DOWN}"
$HotkeyMap[47][1] = 2088
$HotkeyMap[48][0] = "{NUMLOCK}"
$HotkeyMap[48][1] = 2192
$HotkeyMap[49][0] = ","
$HotkeyMap[49][1] = 188

; the following keys are either not currently possible to set, or they are duplicates depends on other system conditions, such as when NumLock is off
$HotkeyMap[50][0] = "{SCROLLLOCK}"
$HotkeyMap[50][1] = 3
$HotkeyMap[51][0] = "{BACKSPACE}"
$HotkeyMap[51][1] = 8
$HotkeyMap[52][0] = "{TAB}"
$HotkeyMap[52][1] = 9
$HotkeyMap[53][0] = "{NUMPAD5}"
$HotkeyMap[53][1] = 12
$HotkeyMap[54][0] = "{ENTER}"
$HotkeyMap[54][1] = 13
$HotkeyMap[55][0] = "{SPACE}"
$HotkeyMap[55][1] = 32
$HotkeyMap[56][0] = "{NUMPAD9}"
$HotkeyMap[56][1] = 33
$HotkeyMap[57][0] = "{NUMPAD3}"
$HotkeyMap[57][1] = 34
$HotkeyMap[58][0] = "{NUMPAD1}"
$HotkeyMap[58][1] = 35
$HotkeyMap[59][0] = "{NUMPAD7}"
$HotkeyMap[59][1] = 36
$HotkeyMap[60][0] = "{NUMPAD4}"
$HotkeyMap[60][1] = 37
$HotkeyMap[61][0] = "{NUMPAD8}"
$HotkeyMap[61][1] = 38
$HotkeyMap[62][0] = "{NUMPAD6}"
$HotkeyMap[62][1] = 39
$HotkeyMap[63][0] = "{NUMPAD2}"
$HotkeyMap[63][1] = 40
$HotkeyMap[64][0] = "{NUMPAD0}"
$HotkeyMap[64][1] = 45
$HotkeyMap[65][0] = "{NUMPADDOT}"
$HotkeyMap[65][1] = 46
$HotkeyMap[66][0] = "\"
$HotkeyMap[66][1] = 226


$gui_Main = GUICreate('Get Hotkey', 220, 90)

$bt = GUICtrlCreateButton('See Value', 10, 50, 200, 30);
    GUICtrlSetState(-1, $GUI_DEFBUTTON)

$hWnd = _WinAPI_CreateWindowEx (0, 'msctls_hotkey32', '', BitOR($WS_CHILD, $WS_VISIBLE), 10, 10, 200, 25, $gui_Main)

_SendMessage($hWnd, $HKM_SETRULES, _
BitOR($HKCOMB_NONE, $HKCOMB_S), _                    ; invalid key combinations
BitOR(BitShift($HOTKEYF_ALT, -16), BitAND(0, 0xFFFF))); add ALT to invalid entries


;Generate random hotkey
$key = ""
If Random(0,1,1) Then $key &= "^"
If Random(0,1,1) Then $key &= "!"
If Random(0,1,1) Then $key &= "+"
If Random(0,1,1) Then
    $key &= $HotkeyMap[Random(0,UBound($HotkeyMap, 1)-1, 1)][0]
Else
    $key &= Chr(Random(Asc("a"), Asc("z"), 1)) ;letter case is irrelevant
EndIf
GUISetState()
MsgBox(0, "Generated default hotkey", $key)

_SendMessage($hWnd, $HKM_SETHOTKEY, HotkeyConvert($key, 1))

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $bt
            $i_HotKey = _SendMessage($hWnd, $HKM_GETHOTKEY)
            Msgbox(0, "Converted hotkey to AU3 format", HotkeyConvert($i_Hotkey))
 ;           If $i_Hotkey = 20 or $i_Hotkey = 144 then ;huh? What's wrong with CapsLock and F3?
 ;               _SendMessage($hWnd, $HKM_SETHOTKEY)
 ;           EndIf
    EndSwitch
WEnd
_WinAPI_DestroyWindow ($hWnd)

Exit
Func HotkeyConvert($hotkey, $type = 0)
    Local $key = ""
    Local $n = UBound($HotkeyMap, 1)-1
    Local $bin = 0
    If $type Then ;reverse convert AU3 to binary
        If StringInStr($hotkey, "+") Then $bin = BitOr($bin, $HOTKEYF_SHIFT)
        If StringInStr($hotkey, "^") Then $bin = BitOr($bin, $HOTKEYF_CONTROL)
        If StringInStr($hotkey, "!") Then $bin = BitOr($bin, $HOTKEYF_ALT)
        $hotkey = StringReplace(StringReplace(StringReplace($hotkey, "!", ""), "^", ""), "+", "") ;Removing any Shift/Ctrl/Alt
        For $i = 0 To $n Step 1
            If $HotkeyMap[$i][0] = $hotkey Then
                $key = $HotkeyMap[$i][1]
                ExitLoop
            EndIf
        Next
        If NOT $key Then
            $key = Asc(StringUpper($hotkey))
        EndIf
        $bin = "0x" & Hex(BitOr(0x100 * $bin, $key))
        Return $bin
    EndIf
  $n_Flag = BitShift($hotkey, 8); high byte
  $i_HotKey = BitAND($hotkey, 0x8FF); low byte this will include Home, Insert, etc without Shift, Ctrl and Alt
  $hotkeyAssignment = ''
  If BitAND($n_Flag, $HOTKEYF_SHIFT) Then $hotkeyAssignment &= '+'
  If BitAND($n_Flag, $HOTKEYF_CONTROL) Then $hotkeyAssignment &= '^'
  If BitAND($n_Flag, $HOTKEYF_ALT) Then $hotkeyAssignment &= '!'
    For $i = 0 TO $n Step 1
        If $HotkeyMap[$i][1] = $i_Hotkey Then
            $key = $HotkeyMap[$i][0]
            ExitLoop
        EndIf
    Next
    If NOT $key Then
    $i_HotKey = BitAND($hotkey, 0xFF)
    $key = StringLower(Chr($i_Hotkey)) ;any letter type of keys should be lower case to avoid confusion as capital "A" = Shift + a
    EndIf
    $hotkeyAssignment &= $key
    Return $hotkeyAssignment
EndFunc

Func _ExcludeHotkey()
    _SendMessage(_WinAPI_GetFocus(), $HKM_SETHOTKEY)
EndFunc

 

Link to post
Share on other sites
  • Moderators

I'm with Melba, I don't understand the intent. Are you saying that, regardless of which key the user hits, it would open Notepad?

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to post
Share on other sites

Perhaps one of these might help, especially the second link.

 

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to post
Share on other sites
4 hours ago, JLogan3o13 said:

Jestem z Melbą, nie rozumiem intencji. Czy mówisz, że niezależnie od tego, który klucz trafi użytkownika, otworzy się Notatnik?

just i want write to inputbox example key "A" click on button Ok then press on keyboard key "A" and next automatically run the notepade is is possible to do?? i want to run notepade after set key "A" in the inputbox field clicking on button Ok and press "A" on keyboard then run it notepad now you guys understand what i want to do? :D   but it must be for random all keys in keyboard

Edited by mar3011
Link to post
Share on other sites
  • Moderators

That's awesome, but you still haven't answered the question - what are you trying to accomplish? And why randomize the keys? That is going to make the task nigh impossible.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to post
Share on other sites

I think I see what he's trying to do, behind the apparent language barrier:  A message box saying "press A to continue", next time it might say "press K to continue", etc., with the letter choice being randomized.  Such a dialog might be intended to force the user to pay attention to the dialog every time rather than just pressing keys by rote.  Using it to start Notepad is probably just an example.  Doesn't look that difficult.

Link to post
Share on other sites

 
Global $sInput = InputBox("Set Hotkey", "Enter the letter you want to use as a Hotkey!")
HotKeySet($sInput, "_Hotkey")
HotKeySet("{Esc}", "_Exit")
While 1
    Sleep(10)
WEnd

Func _Hotkey()
    MsgBox(0, "", "Hotkey pressed")
EndFunc

Func _Exit()
    Exit
EndFunc
I found what I was looking for but now I want it to work and open something like  the Notepad example ,after press any keys.
Link to post
Share on other sites

In this example:-
    the hot key "Alt+h" allows you to set your own hot key to start notepad; and,
    the hot key "Alt+r" automatically sets a random hot key for you to start notepad.

HotKeySet("!h", "_SetHotkey") ; Press Alt+h to initilize hotkey
HotKeySet("!r", "_RandHotkey") ; Press Alt+r for random hotkey
HotKeySet("{Esc}", "_Exit")
Global $sInput

While 1
    Sleep(10)
WEnd


Func _RandHotkey()
    HotKeySet($sInput) ; Erase any previous HotKey.
    Local $aKey = ["!", "+", "^", ""], $aKeyDiscription = ["Alt+", "Shift+", "Ctrl+",""] ; Key and its description arrays
    Do
        Local $iPreKey = Random(0, 3, 1)
        Local $iPostKey = Chr(Random(97, 122, 1)) ; Gets one English lowercase alphabet ASCII character.
        $sInput = $aKey[$iPreKey] & $iPostKey
    Until $sInput <> "!h" Or $sInput <> "!r" ; Will not overwrite existing two HotKeys

    MsgBox(0, "Set Hotkey", 'New Hotkey is now "' & $aKeyDiscription[$iPreKey] & $iPostKey & '".')
    HotKeySet($sInput, "_Hotkey")
EndFunc   ;==>_RandHotkey

Func _SetHotkey()
    HotKeySet($sInput) ; Erase any previous HotKey.
    $sInput = InputBox("Set Hotkey", 'Enter the letter (e.g. "!a") you want to use as a Hotkey (e.g. Alt+a).')
    HotKeySet($sInput, "_Hotkey")
EndFunc   ;==>_SetHotkey

Func _Hotkey()
    Run("NotePad")
EndFunc   ;==>_Hotkey

Func _Exit()
    Exit
EndFunc   ;==>_Exit

 

Edited by Malkey
Changed $sInput to a global variable
Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By DJ143
      I have a autoit exe file which is used in upload/browse file functionality.  This has been integrated with selenium framework and I am invoking the autoit exe using Java process and runtime. 
      Now the issue is when I run the scripts and invoke the autoit exe in local it works perfectly.  But when I use selenium grid or jenkins to run the scripts in another windows server it is not working.
      Can anyone please suggest any solution for this?
    • By Hermes
      Hello, the script below will read column A from an excel file - and if a value matches in the browser, it will click the corresponding link and click on a specific button to paste the data, then writes "Completed" in Column B. It will continue to read from the excel file and do the same thing for all the remaining rows.
      #Include "Chrome.au3" #Include "wd_core.au3" #Include "wd_helper.au3" #Include "WinHttp.au3" #include <MsgBoxConstants.au3> #include <File.au3> #include <IE.au3> #include <Array.au3> #include <INet.au3> #include <AutoItConstants.au3> #include <WinAPIFiles.au3> #include <GDIPlus.au3> #include <Excel.au3> #Include "WinHttp.au3" #Include "_HtmlTable2Array.au3" Local $sDesiredCapabilities, $sSession SetupChrome() _WD_Startup() $sSession = _WD_CreateSession($sDesiredCapabilities) _WD_LoadWait($sSession) _WD_Navigate($sSession, "table1.html") _WD_LoadWait($sSession) _WD_WaitElement($sSession, $_WD_LOCATOR_ByXPath, "//table[@class='main']") Local $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//table[@class='main']") ;ConsoleWrite ("mat-table " & $sElement & @CRLF) Local $aArray1 = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, ".//td[contains(@class,'data')]", $sElement, True) sleep(1000) For $i = 0 to UBound($aArray1) - 1 $aArray1[$i] = _WD_ElementAction($sSession, $aArray1[$i], 'text') Next ;_ArrayDisplay($aArray1) ;Email variables $SmtpServer = "" ; address for the smtp-server to use - REQUIRED $FromName = "Hermes" ; name from who the email was sent $FromAddress = "sender@gmail.com" ; address from where the mail should come $ToAddress = "recipient@gmail.com" ; destination address of the email - REQUIRED, use commas (,) to add more email addresses $Subject = "File not found" ; subject from the email - can be anything you want it to be $Body = "File not found!" ; the messagebody from the mail - can be left blank but then you get a blank mail $AttachFiles = "" ; the file(s) you want to attach seperated with a ; (Semicolon) - leave blank if not needed $CcAddress = "" ; address for cc - leave blank if not needed $BccAddress = "" ; address for bcc - leave blank if not needed $Importance = "High" ; Send message priority: "High", "Normal", "Low" $Username = "" ; username for the account used from where the mail gets sent - REQUIRED $Password = "" ; password for the account used from where the mail gets sent - REQUIRED $IPPort = 25 ; port used for sending the mail $ssl = 0 ; enables/disables secure socket layer sending - put to 1 if using httpS $tls = 0 ; enables/disables TLS when required Local $oAppl = _Excel_Open() Local $sWorkbook = "c:\test.xlsx" Local $oWorkbook = _Excel_BookOpen($oAppl, $sWorkbook) ;open excel and pass both parameters If FileExists($sWorkbook) Then ;Check if the file exist. Local $oAppl = _Excel_Open() Local $sWorkbook = "c:\test.xlsx" Local $oWorkbook = _Excel_BookOpen($oAppl, $sWorkbook) ;open excel and pass both parameters Local $aArray2 = _Excel_RangeRead($oWorkbook,Default,$oWorkbook.ActiveSheet.Usedrange.Columns("A:A")) Local $iIdx Local $Skipline = 0 ;0==> first line Do Local $temprf For $i = 0 To UBound($aArray2) - 1 $temprf &= $aArray2[$i] _WD_WaitElement($sSession, $_WD_LOCATOR_ByXPath, ".//a[contains(@class,'edit') and contains(text(),'Edit')]") Local $aElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, ".//a[contains(@class,'edit') and contains(text(),'Edit')]", $sElement, True) $iIdx = _ArraySearch($aArray1, $aArray2[$i]) If @error Then ContinueLoop _WD_ElementAction($sSession, $aElement[$iIdx], 'click') If $i < $Skipline Then ContinueLoop $oRange = $oWorkbook.ActiveSheet.Range("B" & $i + 1 & ":XFD" & $i + 1) _Excel_RangeCopyPaste($oWorkbook.Activesheet, $oRange) ;Paste Local $oTest4 = _WD_FindElement($sSession, $_WD_LOCATOR_ByCSSSelector, "pastebutton") _WD_ElementAction($sSession, $oTest4, 'click') Sleep(1000) ;Save Button Local $save3 = _WD_FindElement($sSession, $_WD_LOCATOR_ByCSSSelector, "button.button") _WD_ElementAction($sSession, $save3, 'click') _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, "Completed", "B" & $i+1) sleep(1000) Next Until (Not @error) _Excel_Close($oWorkbook) Else _INetSmtpMailCom($SmtpServer, $FromName, $FromAddress, $ToAddress, $Subject, $Body, $CcAddress, $BccAddress, $Importance, $Username, $Password, $IPPort, $ssl, $tls) Exit EndIf _WD_LoadWait($sSession) ;Attaching files to emails Func _INetSmtpMailCom($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject = "", $as_Body = "", $s_CcAddress = "", $s_BccAddress = "", $s_Importance="Normal", $s_Username = "", $s_Password = "", $IPPort = 25, $ssl = 0, $tls = 0) Local $objEmail = ObjCreate("CDO.Message") $objEmail.From = '"' & $s_FromName & '" <' & $s_FromAddress & '>' $objEmail.To = $s_ToAddress Local $i_Error = 0 Local $i_Error_desciption = "" If $s_CcAddress <> "" Then $objEmail.Cc = $s_CcAddress If $s_BccAddress <> "" Then $objEmail.Bcc = $s_BccAddress $objEmail.Subject = $s_Subject If StringInStr($as_Body, "<") And StringInStr($as_Body, ">") Then $objEmail.HTMLBody = $as_Body Else $objEmail.Textbody = $as_Body & @CRLF EndIf $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = $s_SmtpServer If Number($IPPort) = 0 then $IPPort = 25 $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = $IPPort ;Authenticated SMTP If $s_Username <> "" Then $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1 $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusername") = $s_Username $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = $s_Password EndIf ; Set security params If $ssl Then $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True If $tls Then $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendtls") = True ;Update settings $objEmail.Configuration.Fields.Update ; Set Email Importance Switch $s_Importance Case "High" $objEmail.Fields.Item ("urn:schemas:mailheader:Importance") = "High" Case "Normal" $objEmail.Fields.Item ("urn:schemas:mailheader:Importance") = "Normal" Case "Low" $objEmail.Fields.Item ("urn:schemas:mailheader:Importance") = "Low" EndSwitch $objEmail.Fields.Update ; Sent the Message $objEmail.Send $objEmail="" EndFunc ;==>_INetSmtpMailCom Local $aDir = _FileListToArrayRec(@TempDir, "scoped_dir*;chrome_*", $FLTAR_FOLDERS, $FLTAR_NORECUR, $FLTAR_NOSORT, $FLTAR_FULLPATH) Sleep(2000) For $i = 1 To $aDir[0] DirRemove($aDir[$i], $DIR_REMOVE) Next _WD_LoadWait($sSession) _WD_Shutdown() Func SetupChrome() _WD_Option('Driver', 'chromedriver.exe') _WD_Option('Port', 9515) _WD_Option('DriverParams', '--log-path="' & @ScriptDir & '\chrome.log"') $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true, "args":["start-maximized","disable-infobars"]}}}}' EndFunc ;==>SetupChrome If the excel file doesn't exists in the folder, it will send an email to a specific recipient.
      What i am trying figure out now is if the excel crashes while the script/loop is running, I want to relaunch the excel file continue to the last row before the excel crashed. So if the value of column B is not marked as "completed", it should continue from that row
      Appreciate any help that I can get to achieve this.
      table1.html test.xlsx
    • By adityaparakh
      Hello ,
      I am trying to use Websockets in AutoIt.
      It is to fetch live stock market prices , API is provided and documentation available for python language.
      The link for the code snippet is :
      https://symphonyfintech.com/xts-market-data-front-end-api-v2/#tag/Introduction
      https://symphonyfintech.com/xts-market-data-front-end-api-v2/#tag/Instruments/paths/~1instruments~1subscription/post
       
      https://github.com/symphonyfintech/xts-pythonclient-api-sdk
       
      Second Link is to subscribe to a list of ExchangeInstruments.
      Now I would like to get live stock ltp (LastTradedPrice) for a few stocks whose "ExchangeInstrumentID" I know.
      I am able to use the WinHttp object to perform actions using simple codes like below :
      I have the secretKey and appkey and can generate the needed token. And get the unique ExchangeInstrumentID.

      Below code is just for example of how I am using WinHttp. Unrelated to socket part.
      Global $InteractiveAPItoken = IniRead(@ScriptDir & "\Config.ini", "token", "InteractiveAPItoken", "NA") $baseurl = "https://brokerlink.com/interactive/" $functionurl = "orders" $oHTTP = ObjCreate("winhttp.winhttprequest.5.1") $oHTTP.Open("POST", $baseurl & $functionurl, False) $oHTTP.SetRequestHeader("Content-Type", "application/json;charset=UTF-8") $oHTTP.SetRequestHeader("authorization", $InteractiveAPItoken) $pD = '{ "exchangeSegment": "NSEFO", "exchangeInstrumentID": ' & $exchangeInstrumentID & ', "productType": "' & $producttype & '", "orderType": "MARKET", "orderSide": "' & $orderside & '", "timeInForce": "DAY", "disclosedQuantity": 0, "orderQuantity": ' & $qty & ', "limitPrice": 0, "stopPrice": 0, "orderUniqueIdentifier": "' & $orderidentifier & '"}' $oHTTP.Send($pD) $oReceived = $oHTTP.ResponseText $oStatusCode = $oHTTP.Status
          
          
      But am struggling to understand and use socket.
      Would be of great help if you can have a look at the link mentioned above and help with the code sample for AutoIt.
      To connect and listen to a socket.
      Thanks a lot
       
    • By Hermes
      Hi, I have a site that has the following elements below: 
      <div>More element here</div> <div>More element here</div> <div>More element here</div> When I do this in Auto It:
      Local $oSelectDiv = _WD_FindElement($sSession, $_WD_LOCATOR_ByCSSSelector, "div") _WD_HighlightElement($sSession, $oSelectDiv, 1) I also tried to add [3], but it doesnt seems to work:
      Local $oSelectDiv = _WD_FindElement($sSession, $_WD_LOCATOR_ByCSSSelector, "div[3]") _WD_HighlightElement($sSession, $oSelectDiv, 1) It always highlight the first one, but I am trying to highlight the 3rd in the list. Is there anyway to select the 3rd div without having to add any class/id in the divs, and without using XPATH? The structure of the elements in that site were built that way.
    • By meety
      My au3 script program needs administrator privileges on win10 to be executed correctly, because it needs to be added to the boot---Script code:RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run", @ScriptName, "REG_SZ", @ScriptFullPath)
      I need to let the program automatically get administrator privileges, so I use a function of #RequireAdmin. Although the program can be added to the boot, but does not execute after system boot up? why is that?
      What should I do?
      --------------------------------------------------------------------
      Update:
      I found that after using the #RequireAdmin function, the program cannot be executed after system boot up.
      An example is given below. after it is compiled, it will not be executed after system boot up in the following two ways.
      1. C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp\
      2. RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run", @ScriptName, "REG_SZ", @ScriptFullPath)
      why is that?
      example
      #include <MsgBoxConstants.au3>
      #RequireAdmin
      Func test()
          MsgBox(0, "", "this is test message")
      EndFunc   ;==>test
      test()
       
       
×
×
  • Create New...