barkeeper

Too many enters in script

11 posts in this topic

Hi there, not sure if this is the right place, but I'm building a script for using premade answers in chat. It works and outputs the answers (stored in an ini file based on:  answer name = answer it also works with a new line if there is a tag <enter> in the answer text in the ini file. Now the problem is, that after the answer is pasted in the chat (you bring up the interface with ctrl+1) it gives an enter, thus sending the output straight away. I would like to be able to review the answer before sending it. can anyone help me by telling what's wrong in the script, I tried replacing the @crlf in the script with other options, no luck. Thanks in advance! 

antwoorden.au3

antwoorden.ini

Share this post


Link to post
Share on other sites



Guess we need to understand what character needs to be send in stead of @CRLF (<enter>) for a newline in your chat client.
Any idea or tried Shift+Enter or just @lf or @cr?

Jos


Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
On ‎25‎-‎1‎-‎2017 at 5:55 PM, Jos said:

Guess we need to understand what character needs to be send in stead of @CRLF (<enter>) for a newline in your chat client.
Any idea or tried Shift+Enter or just @lf or @cr?

Jos

I tried @LF and @CR, no luck. how would I achieve a Shift+Enter instead of the regular enter, can't figure it out I'm afraid.

Share this post


Link to post
Share on other sites

Also you could use Op('ExpandVarStrings', 1) then in your Ini file you can write your <Enter> as @CRLF@ these will be automatically expanded upon reading the ini file.  For example:

[answers]
answer1=default answer line 1@CRLF@line 2 
answer2=default answer line 1@CRLF@line 2

 

Share this post


Link to post
Share on other sites
13 minutes ago, Subz said:

You could just use StringReplace for example:

If StringInStr($sAnswer,"<enter>") Then $sAnswer =StringReplace($sAnswer,"<enter>", @CRLF)

 

Hi Subz, Thanks for looking at the script. The StringReplace function does make it a little better, but what happens with it is that the first line in the answer .ini file is posted (with enter) and the second one is not (like I want it to be). Any ideas ? The script is meant for providing quick answers to chats we do with Skype for Business, and we would like to review the pasted "default" text, before sending

Share this post


Link to post
Share on other sites
14 minutes ago, Subz said:

Also you could use Op('ExpandVarStrings', 1) then in your Ini file you can write your <Enter> as @CRLF@ these will be automatically expanded upon reading the ini file.  For example:

[answers]
answer1=default answer line 1@CRLF@line 2 
answer2=default answer line 1@CRLF@line 2

 

Can you show me a line of code using the ExpandVarStrings in my current script so I get an idea. I'm really new to this. Cheers

Share this post


Link to post
Share on other sites

#10 ·  Posted

This is a little quick and dirty but maybe you want to try something like this:

#include <Array.au3>
#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>

Opt('ExpandVarStrings', 1)

Global $hGUI
Global $bGuiHide = True
Global $sIni = @ScriptDir & "\antwoorden.ini"
Global $aIni = IniReadSection($sIni, 'answers')
    If @error Then Exit MsgBox(16, 'Error', 'Unable to read ini file')

HotKeySet("^1", "_GuiToggle")

Example()

While 1
    Sleep(50)
WEnd

Func Example()
    $hGUI = GUICreate("Example", 300, 200)

    Local $idComboBox = GUICtrlCreateCombo("", 10, 10, 280, 20, $CBS_DROPDOWNLIST)
    Local $idEditBox = GUICtrlCreateEdit('', 10, 40, 280, 120)
    Local $idClose = GUICtrlCreateButton("Close", 210, 170, 85, 25)

    GUICtrlSetData($idComboBox, _ArrayToString($aIni, '|', 1, -1, '|', 0, 0))

    If $bGuiHide = True Then
        GUISetState(@SW_HIDE, $hGUI)
    Else
        GUISetState(@SW_SHOW, $hGUI)
    EndIf

    Local $sComboRead = ""

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE, $idClose
                GUISetState(@SW_HIDE)
                $bGuiHide = True
            Case $idComboBox
                $sComboRead = GUICtrlRead($idComboBox)
                $sIniRead = IniRead($sIni, 'answers', $sComboRead, "Sorry No answer available")
                GUICtrlSetData($idEditBox, $sIniRead)
        EndSwitch
    WEnd
EndFunc

Func _GuiToggle()
    If $bGuiHide = True Then
        $bGuiHide = False
        GUISetState(@SW_SHOW, $hGUI)
    Else
        $bGuiHide = True
        GUISetState(@SW_HIDE, $hGUI)
    EndIf
EndFunc

antwoorden.ini

[answers]
answer1=default answer line 1@CRLF@line 2 
answer2=default answer line 1@CRLF@line 2
test=test@CRLF@not recommended@CRLF@http://www.mywebsite.com/

 

Share this post


Link to post
Share on other sites

#11 ·  Posted

12 minutes ago, Subz said:

This is a little quick and dirty but maybe you want to try something like this:

expandcollapsepopup
#include <Array.au3>
#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>

Opt('ExpandVarStrings', 1)

Global $hGUI
Global $bGuiHide = True
Global $sIni = @ScriptDir & "\antwoorden.ini"
Global $aIni = IniReadSection($sIni, 'answers')
    If @error Then Exit MsgBox(16, 'Error', 'Unable to read ini file')

HotKeySet("^1", "_GuiToggle")

Example()

While 1
    Sleep(50)
WEnd

Func Example()
    $hGUI = GUICreate("Example", 300, 200)

    Local $idComboBox = GUICtrlCreateCombo("", 10, 10, 280, 20, $CBS_DROPDOWNLIST)
    Local $idEditBox = GUICtrlCreateEdit('', 10, 40, 280, 120)
    Local $idClose = GUICtrlCreateButton("Close", 210, 170, 85, 25)

    GUICtrlSetData($idComboBox, _ArrayToString($aIni, '|', 1, -1, '|', 0, 0))

    If $bGuiHide = True Then
        GUISetState(@SW_HIDE, $hGUI)
    Else
        GUISetState(@SW_SHOW, $hGUI)
    EndIf

    Local $sComboRead = ""

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE, $idClose
                GUISetState(@SW_HIDE)
                $bGuiHide = True
            Case $idComboBox
                $sComboRead = GUICtrlRead($idComboBox)
                $sIniRead = IniRead($sIni, 'answers', $sComboRead, "Sorry No answer available")
                GUICtrlSetData($idEditBox, $sIniRead)
        EndSwitch
    WEnd
EndFunc

Func _GuiToggle()
    If $bGuiHide = True Then
        $bGuiHide = False
        GUISetState(@SW_SHOW, $hGUI)
    Else
        $bGuiHide = True
        GUISetState(@SW_HIDE, $hGUI)
    EndIf
EndFunc

antwoorden.ini

[answers]
answer1=default answer line 1@CRLF@line 2 
answer2=default answer line 1@CRLF@line 2
test=test@CRLF@not recommended@CRLF@http://www.mywebsite.com/

 

I'll take a look at it, appreciate it, thanks!

Share this post


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

  • Similar Content

    • Eggsplorer
      By Eggsplorer
      Hi,
      Ich hab ein Script für Windows Updates, dass nach dem OOBE aufgerufen werden soll. Run/RunOnce ist daher nicht möglich.
      Stattdessen möchte ich das Script in den Autostart schreiben lasse. Wenn die OOBE beendet wird und der Administrator angemeldet wird, soll das Update-Script einmalig aufgerufen werden und sich anschl. selbst löschen.
      Lang rede, kurzer Sinn:
      Wie kann ich folgendes Script in den Autostart schreiben?
      RunWait(@ComSpec & " /c " & "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -File C:\UA\Scripts\win-updates.ps1 -MaxUpdatesPerCycle 100 -RestartRequired 1", "") Ich würde ungern eine BAT oder EXE reinkopieren, da ich es unsauber finde. Die müsste ja auch zusätzlich irgendwo liegen.
      Danke
      Eggsplorer
    • FrancescoDiMuro
      By FrancescoDiMuro
      Good morning everyone
      I worked a bit on a little project of mine, and I managed to do what I was trying to do, or, automate a quiz in AutoIt.
      Now, everything works fine but, in order to achieve what I'm trying to achive, I'd like to make this script run faster.
      I'll attach a portion of the code in order to let you understand what my script does.
      $objIE_h1 = _IETagNameGetCollection($objIE, "h1") ; Take the text of the answer If @error Then ConsoleWrite("Errore durante la lettura degli h1 nella pagina. - Errore: " & @error & @CRLF) Else For $objElement In $objIE_h1 $strInnerText = $objElement.innerText Next Select Case StringInStr($strInnerText, "QUESTION") ; Here is the question ; PS4 PRO $objSpans = _IETagNameGetCollection($objIE, "span") ; Answers are stored here For $objElement In $objSpans If $i >= 4 Then $strAnswer = $objElement.innerText ; Take the text of the answer n° 0, 1, 2, 3 If StringInStr($strAnswer, "CORRECT ANSWER") Then ; If I match the correct answer, then, I have to click on the input with answer id = answer_i $j = $i - 4 $objInput = _IEGetObjById($objIE, "answer_" & $j) If @error Then ConsoleWrite("Errore durante la lettura della risposta #" & $i & " - Errore: " & @error & @CRLF) Else _IEAction($objInput, "click") If @error Then ConsoleWrite("Errore durante il click sull'elemento. - Errore: " & @error) Else ConsoleWrite($j & ") Risposta: " & $strAnswer & @CRLF) ExitLoop EndIf EndIf EndIf $i+=1 Else $i+=1 EndIf Next $i = 0 $j = 0 This is what my script does.
      Questions are 20, in which I have 15 multiple choice question, 2 images ( on which I use _IEImgClick() ), and 3 text inputs ( a simple send with the text I have to enter ).
      How can I make all of these, faster?
      If I reach this goal, I've probably done one of my best goals in life, and I'd like to share my happiness with you, giving a huge donation to this fantastic community!
      Thanks for your help
    • WiorDi37
      By WiorDi37
      Hello, Everyone!
      I want when clicking the exit button the window will close. If content changes upon exit the program will automatically choose not save.
      Look forward to the help, thanks.
      #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <AutoItConstants.au3> $GUI = GUICreate("Form1", 220, 119, 192, 124, $WS_SYSMENU) GUISetFont(10, 400, 0, "Tahoma") GUICtrlCreateGroup("Chuẩn bị trình chiếu", 16, 16, 185, 65) $ok_Button = GUICtrlCreateButton("Ok", 32, 48, 75, 25) $exit_Button = GUICtrlCreateButton("Exit", 112, 48, 75, 25) GUICtrlCreateGroup("", -99, -99, 1, 1) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $ok_Button ShellExecute(@MyDocumentsDir&'\Dich-thuat\Short-Document.pdf', "", "", Default, @SW_MAXIMIZE) WinWaitActive("Data and Computer Communications (Eighth Edition) - Google Chrome") ShellExecute(@MyDocumentsDir&'\Dich-thuat\Document.rtf', "", "", Default, @SW_MAXIMIZE) WinWaitActive("Document.rtf [Compatibility Mode] - Word") ShellExecute(@MyDocumentsDir&'\Dich-thuat\Presentation1.pptx', "", "", Default, @SW_MAXIMIZE) WinWaitActive("Presentation1.pptx - PowerPoint") MouseClick("left", 1381, 886, 1) Sleep(2000) MsgBox(64, "Thông báo", "Đã chuẩn bị xong") Case $exit_Button WinClose("Presentation1.pptx - PowerPoint") ;I need help handling this place Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd  

    • badcoder123
      By badcoder123
      Hey everyone,
      I've been messing around with some new things and adlibs look extremely useful/interesting, however, I can't seem to get it to work.. Here's what I have
      HotKeySet("{F1}", "_Exit") $qCount = 1 Global $_Timer AdlibRegister($_Timer, 1000) AdlibUnRegister($_Timer) While 1 SoundPlay(@WindowsDir & "\media\tada.wav", 1) $qCount += 1 ToolTip('"Tada" has been played ' & $qCount & " times",200,200) WEnd Func _Timer() Local Static $iCount += 1 ConsoleWrite($iCount) If $iCount = 20 Then ConsoleWrite("iCount is at " & $iCount) EndFunc Func _Exit() Exit EndFunc Basically I want it to call the _Timer function but it doesn't seem to work :/ any ideas?
    • DagSa
      By DagSa
      Try to find a solution for help files to my autoit executable.
      Its installed from simple XP-POS cash computers to desktop with windows 7, 8, 10.
      The compiled AutoIt program itself work everywhere, but the help file??
      I need a help file called from from the program and I don't really know what working best in all OS platforms.
      1. A wordfile is helpful enough, but word is not installed everywhere.
      2. RTF is very big files with pictures.
      3. I could save it as pdf, but not all have it either.
      4. Tried  .MHT file, but downside is browser could cover hole screen if browser closed this way. I have not found any way to resize it to specific size when open up.
      5. Use of IE.au3 lib. Well it could open mht files ,but always got question about use it as default browser or not. Think this also make IE browser lose control so I could not resize.
      6. Look at making a  .CHM file, but I don't think its the future do use that format. (.hlp is no no and old)

      Any tips of do it in autoit or make a call to open up in some nice format working everywhere.