Jump to content
Sign in to follow this  

Recommended Posts

I wonder if it would be possible for autoit to obtain data from clipboard and compare it with a "notepad file" or something. And if there is a match then it must replace the word with the other word that is behind the = mark.

Example:

1. I copy: "car accident"

2. The program must read this.

3. Search through a database.

  • DATABASE(notepad?): car accident = dial 112
4. Match? then copy data behind the = mark to clipboard.
  • copy dial 112 to clipboard in this example
5. Then if you perform the windows PASTE function then "dial 112" must appear.

Thanks in advance,

Jeanpierre

Share this post


Link to post
Share on other sites

Hi, Jeanpierre92. You should be able to do this with AutoIt, yes. Take a look in the help file at ClipPut and ClipGet to get you started. Post your code once you have a go at it, and we'll help you along :oops:

Share this post


Link to post
Share on other sites

Well I have encountered a problem:

The text from clipboard can contain different types of sentences but it can also contain only one word.

Example:

Clipboard: fire

Database: there is a fire = dial 112

Result: there is a fire = dial 112

Clipboard: dial

Database: there is a fire = dial 112

Result: there is a fire = dial 112

Clipboard: fire

Database: fire = dial

Result: fire = dial

Error: Array variable has incorrect number of subscripts or subscript dimension range exceeded.:

So the problem is that if the clipboard string is small then if gives the @error, but also when the clipboard string is to long.

The amount of $clipparts[~] must also be precisely the amount of the clipparts there are at that moment.

Also the:

If $clipparts[1] = $stringparts[1] Or $clipparts[1] = $stringparts[2] Or $clipparts[2] = $stringparts[1] Or $clipparts[2] = $stringparts[2] Then

Doesn't feel good because of there are 5 clipparts then there must be alot of "$clipparts[1] = $stringparts[1]" to compare.(this amount must be variable to)

I dont know how to get this done.

Thanks in advance for the tips/help

Full script:

;Checking if the file is ready for reading
Local $file = FileOpen("database.txt", 0)
If $file = -1 Then
    MsgBox(0, "Error", "Cant open file")
    Exit
EndIf

While 1
    Local $line = FileReadLine($file)
    If @error = -1 Then
    ExitLoop
    EndIf
    MsgBox(0, "Line read:", $line)
$stringparts = StringSplit($line, "=")
MsgBox(0, "StringParts", "Numer of StringParts returned: " & $stringparts[0] & " Namelijk: " & $stringparts[1] & " En: " & $stringparts[2])

$clipboard = ClipGet() ;Reading clipboard data
$clipparts = StringSplit($clipboard, " ")
MsgBox(0, "ClipParts", "Numer of Clipparts returned: " & $clipparts[0] & " Namelijk: " & $clipparts[1] & " En: " & $clipparts[2])

If $clipparts[1] = $stringparts[1] Or $clipparts[1] = $stringparts[2] Or $clipparts[2] = $stringparts[1] Or $clipparts[2] = $stringparts[2] Then
    MsgBox(0, "Test", "Match!")
    ;Read string behind = mark and copy it to clipboard //ClipPut()
Else
    MsgBox(0, "Test", "No Match!")
    EndIf
WEnd
MsgBox(0, "End", "End of database")

Share this post


Link to post
Share on other sites

jeanpierre92,

Can you provide an example of "database.txt"? (more than the couple of lines that you posted)

This looks like a kind of EMS expert system (the user enters something and a DB returns 1 or more actions to take). Is that correct?

Why use the clipboard as opposed to a GUI of somesort?

What starts the script?

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

Can you provide an example of "database.txt"? (more than the couple of lines that you posted)

Well the database.txt is quite empty because I will start with database.txt when everythings works proper.

Example of "database.txt":

something with more words=oneword

oneword= something with more words

oneword=oneword

something with more words=something with more words

EDIT:

It also got spit the sentense and search for matches:

example:

to annihilate=destruction

annihilate is in the clipboard then it still has to recognize and give me the right sentense

This looks like a kind of EMS expert system (the user enters something and a DB returns 1 or more actions to take). Is that correct?

Yes it's almost the same. In this case you can enter 1 or more words(not more than 5 words I think). Then the DB must provide me the right sentence.(which can also be more than 1 word)

Why use the clipboard as opposed to a GUI of somesort?

Well thats the point of my script. It has to be some kind of a "fast response". I copy a word or sentense and there must me an immediately response. So without GUI's or windows.

Its like a translate website but then only for words/sentenses that I want. And I dont want to look it up or something, just COPY and insta PASTE.

It has to be a database.txt which I can edit whenever I want ofcourse :oops:

What starts the script?

When its done and everything works proper I convert it to a .exe and then I can use it whenever I want and also stop it when I want to.

The this what I dont know is how to define the max $clipparts[~] and $stringparts[~]

$clipparts[0] knows how many strings it has created, it has to be something with this.

I also has to be a everlasting flow. With that I mean that when I copy something it has to check and if can he must replace it for the sentence.

Then the script must pause I think until I have replaced the clipboard for another sentense or word.

I hope you get the point and thanks for the help.

Edited by Jeanpierre92

Share this post


Link to post
Share on other sites

JeanPierre92,

This is something like what you are describing...

#include <array.au3>
#include <file.au3>
; this is to exit the script
HotKeySet("{Esc}", "_fini")

#cs
 The database looks like this
   fire = call 911
   poison = call 911 with the kind of substance ingested
   car accident = call 911 with severity of injuries
   pizza = dominoes
#ce
; changed read routine to use an array
Local $array_DB
_FileReadToArray("c:tmpdatabase.txt", $array_DB)
If @error Then
 If MsgBox(17, "Response DB Build Error", ' Error = ' & @error) = 2 Then Exit
EndIf
While 1
 $clipboard = ClipGet() ;Reading clipboard data
 For $i = 1 To UBound($array_DB) - 1
  $a10 = StringSplit($array_DB[$i],'=')
  ; the following tests that there is 1 "=" sign
  If $a10[0] <> 2 Then
   If MsgBox(17,"Invalid data in Response DB","Current data line [" & $array_DB[$i] & ']') = 2 Then Exit
  endif
  ; the following tests for a match and issues the message if equal
  If StringStripWS($a10[1],3) = StringStripWS($clipboard,3) Then
   MsgBox(48,'Emergency Response Action',$a10[2])    ; there are better ways to do this
   ClipPut("")
  endif
 next
 Sleep(1000)  ; check the clipboard every 5 seconds
wend
Func _fini()
 ; add any exit logic here
 Exit
endfunc

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

JeanPierre92,

Here's kind of a cute spin on the display. The GUI is invisible and the message pops out on top of whatever is on the display.

Fixed database.txt to allow blank lines...

#include <array.au3>
#include <file.au3>
#include <string.au3>
#include <windowsconstants.au3>
#include <guiconstantsex.au3>
#include <WINAPI.au3>
; this is to exit the script
HotKeySet("{Esc}", "_fini")

#cs
 The database looks like this
   fire = call 911
   poison = call 911 with the kind of substance ingested
   car accident = call 911 with severity of injuries
   pizza = dominoes

   what is this = nothing
#ce
; changed read routine to use an array
Local $array_DB
_FileReadToArray("c:tmpdatabase.txt", $array_DB)
If @error Then
 If MsgBox(17, "Response DB Build Error", ' Error = ' & @error) = 2 Then Exit
EndIf
While 1
 $clipboard = ClipGet() ;Reading clipboard data
 For $i = 1 To UBound($array_DB) - 1
  If StringLen($array_DB[$i]) = 0 Then continueloop
  $a10 = StringSplit($array_DB[$i],'=')
  ; the following tests that there is 1 "=" sign
  If $a10[0] <> 2 Then
   If MsgBox(17,"Invalid data in Response DB","Current data line [" & $array_DB[$i] & ']') = 2 Then Exit
  endif
  ; the following tests for a match and issues the message if equal
  If StringStripWS($a10[1],3) = StringStripWS($clipboard,3) Then
   _issue_message()
   ClipPut("")
  endif
 next
 Sleep(500)  ; check the clipboard every .5 seconds
wend
Func _issue_message()
 local $gui010 = GUICreate("",700,100 ,-1, -1, $WS_POPUP, $WS_EX_LAYERED)
     GUISetBkColor(0xABCDEF)
 local $lbl010 = guictrlcreatelabel('',10,10,680,680)
     guictrlsetfont($lbl010,24,800)
     GUICtrlSetColor($lbl010,0x990000)
     _WinAPI_SetLayeredWindowAttributes($gui010, 0xABCDEF, 250)
     guisetstate(@sw_show)
     GUICtrlSetData($lbl010,$a10[2])
 Beep(500,1000)
 Sleep(2000)
 GUIDelete($gui010)
endfunc
Func _fini()
 ; add any exit logic here
 Exit
endfunc

; poison

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

Kylomas,

Thanks for all your usefull information. At this moment I am trying to evaluate and understanding your script. I tested your frist script that you made and it works pretty well. I have tweaked some things.

When I copy data to clipboard, now the script also provides me the right information that is at the left of the "=" sign.

If StringStripWS($a10[1],3) = StringStripWS($clipboard,3) Then
   MsgBox(48,'Emergency Response Action',$a10[2])    ; there are better ways to do this
   ClipPut("")
  endif
 
If StringStripWS($a10[2],3) = StringStripWS($clipboard,3) Then
   MsgBox(48,'Emergency Response Action',$a10[1])    ; there are better ways to do this
   ClipPut("")
  endif

The last script that you have send me is a little more complicated and I am trying to understand it.

Give me some time and when I am stuck at something I will reply ;)

Thanks for your interest and time

Jeanpierre

Edited by Jeanpierre92

Share this post


Link to post
Share on other sites

Oke this is so cool ;)

The last script that you gave me is just perfect and works good. Is it possible to write comments in the "database.txt"? Then I can devide some parts/groups that belongs to eachother.

like this:

; firecontroll

fire = call 112

bushfire = call 112 and ask for the firefighters

etc.

; poison cases

poison = call 911 with the kind of substance ingested

etc.

Jeanpierre

Share this post


Link to post
Share on other sites

You could make it an ini file and use IniFileRead or any of the other various Ini* commands to do it more efficiently.


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

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
Sign in to follow this  

  • Similar Content

    • By rudi
      Hi,
      from other postings here as a start I'm quite Close to my Goal of putting formatted text to the clipboard:
      #include-once #include <GUIConstantsEx.au3> #include <GuiRichEdit.au3> #include <WindowsConstants.au3> Global $g_idLblMsg, $g_hRichEdit Example("The first text will be formatted ""as is""" & @CRLF & _ "(Default Font and font size)", "This text is formatted differently") MsgBox(0, "Rich Text copied", "Formatted Text put to clipboard") Func Example($TextDefault, $TextCourier) Local $hGui, $iMsg, $idBtnNext, $iStep = 0 $hGui = GUICreate("Example (" & StringTrimRight(@ScriptName, StringLen(".exe")) & ")", 320, 350, -1, -1) $g_hRichEdit = _GUICtrlRichEdit_Create($hGui, $TextDefault, 10, 10, 300, 220, BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL)) $g_idLblMsg = GUICtrlCreateLabel("", 10, 235, 300, 60) GUISetState(@SW_SHOW) _GUICtrlRichEdit_SetSel($g_hRichEdit, -1, -1) ; set selection behind last CHAR in RTF_EDIT _GUICtrlRichEdit_SetFont($g_hRichEdit, 8, "Courier New") ; change font to 8pt, Courier New _GUICtrlRichEdit_AppendText($g_hRichEdit, @CRLF & $TextCourier) _GUICtrlRichEdit_SetSel($g_hRichEdit, 0, -1) ; select all the content of the RTF_EDIT _GUICtrlRichEdit_Copy($g_hRichEdit) ; put the selection to the clipboard EndFunc ;==>Example  
      Finally the clipboard content has to hold pre-formatted data to be pasted into an email body. for the 2nd part I'd like to add a frame around the text, like I did manually before taking this screenshot.



      Any suggestions, or maybe some absolutely different Approach?
       
      CU, Rudi.
    • By ThePoro
      I have this code 
      It gets variable input from GUI to run a loop and write to a text file then copy it to the clipboard
      But the thing is code runs normally with $px and $py <100 or both > 100 or with $px <10 and $py>100 but It's wrong with 10<$px <100 and $py >100
      Can anyone tell me why?
      Func clone() Local $px = GUICtrlRead($input1) Local $py = GUICtrlRead($input2) Local $temp = "C:\temp.csv" FileDelete($temp) While $px <= $py Local $name = "P"&$px FileWrite($temp, " & $name & ""& @CRLF) $px+= 1 WEnd $a=FileRead($temp) ClipPut($a) MsgBox($MB_ICONINFORMATION,"","Copied to Clipboard") EndFunc  
    • By XinYoung
      HI! ... this is a big one (at least for me) 
      You guys previously helped me copy the used range in column A and paste them into a Website one at a time in a loop. Cool! Now, for another function, I have 2 columns, A and B, and two input boxes in the Website. I'm having a hard time replicating the loop for the 2 columns. 
      This is how I'm opening the Excel workbook (copied from the previous function that only had 1 column). I need to also get the used range in column B.
      Func OpenExcelForCopy() Global $aBBTableData Global $oExcel = _Excel_Open() Global $oWorkbook = _Excel_BookOpen($oExcel, $ChosenFileName, Default, True, True) $oExcel.Sheets("CopyCourses").Activate ;~ Get all used cells in column A:A Global $aSearchItems = _Excel_RangeRead($oWorkbook, 1, $oWorkbook.Sheets("CopyCourses").Usedrange.Columns("A:A")) ;~ Duplicate the $aSearchItems Array Global $aSearchResult = $aSearchItems ;~ Loop through the array starting at 0 until the end of the array which is (Ubound($aSearchItems) - 1) For $i = 0 To UBound($aSearchItems) - 1 $aSearchResult[$i] = SearchCourseForCopy($aSearchItems[$i]) Next _Excel_RangeWrite($oWorkbook, Default, $aSearchResult, "C1") Finished() EndFunc ;==>OpenExcelForCopy Then we eventually get here. I don't think anything needs to change here but I'm not sure. This is where I paste the data from Column A into an input field (which is a search tool in a website). If the search is good, then we get to the tricky part...
      ;~ OK, we logged in and we searched for a course. Lets COPY it! Func CopyCourseBegin() Local $sResult $iSearchIndex = _ArraySearch($aBBTableData, "Course ID", 0, 0, 0, 1, 1, 0) ;~ If the course was not found, do this. If $iSearchIndex = -1 Then ;~ MsgBox(4096, "Search Error", "Item not found") $sResult = "Source Not Found" _Excel_RangeWrite($oWorkbook, Default, $aSearchResult, "C1") ;~ Now go back to the Excel sheet and search for the next one. ;~ If the course was found, begin the COPY process. Else For $i = 0 To UBound($aSearchItems) - 1 $aSearchResult[$i] = CopyCourseNow($aSearchItems[$i]) Next $sResult = "Copied" _Excel_RangeWrite($oWorkbook, Default, $aSearchResult, "C1") EndIf Return $sResult EndFunc ;==>CopyCourseBegin This is the "tricky part" where I'm confused. I can copy and paste what's in column A just fine, but I can't manage to replicate it for column B. I need to paste whats in Column B into "destinationCourseId"
      ;~ The course search was successful. COPY the course now. Func CopyCourseNow($_sSearchResult) ;~ Navigate to the course copy page. _IENavigate($oIE, $urlBBCourseCopy) ;~ Copy the SOURCE course ID from the Excel sheet ;~ Paste whats copied from column A into the Source Course ID text box Local $oForm = _IEGetObjByName($oIE, "selectCourse") Local $oSearchString = _IEFormElementGetObjByName($oForm, "sourceCourseId") _IEFormElementSetValue($oSearchString, $_sSearchResult) ;~ Paste whats copied from column B into the Destination Course ID text box ?!?!?!?! Local $oForm = _IEGetObjByName($oIE, "selectCourse") Local $oSearchString = _IEFormElementGetObjByName($oForm, "destinationCourseId") _IEFormElementSetValue($oSearchString, $_sSearchResult) ;~ Just exit cause im stuck :( _Exit() EndFunc ;==>CopyCourseNow After I paste the data from column A into "sourceCourseId" and column B into "destinationCourseId", I'll make it do some stuff. Then I need it to loop around until the used ranges in column A & B is finished.
      Does the entire code need to change now that there's two columns?
       
       
    • By coffeeturtle
      Programs like Ditto are a great augmentation to the Windows clipboard where it keeps a list of items you copy and paste and you can go back to days, weeks, months later. It also comes in handy for multiple copied items you need to paste over and over again.
      https://sourceforge.net/projects/ditto-cp/
      Windows 10 also now has a clipboard history capability (though not as robust, I think, as Ditto).
      https://www.windowscentral.com/how-use-new-clipboard-windows-10-october-2018-update
      I would like to simulate this type of clipboard history into my own apps independent of Windows' clipboard, but I haven't a clue as to where to begin.
      Thank you in advance for any suggestions, examples, shelved codes. ☺
×
×
  • Create New...