Sign in to follow this  
Followers 0
Jeanpierre92

Is this possible?

12 posts in this topic

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:


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

Oke thats good to know :doh:

:oops: Construction in progress :bye:

Thanks, posting script when I am stuck

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

#6 ·  Posted (edited)

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,

The comment for the sleep is wrong. The clip board is checked every second.

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

#10 ·  Posted (edited)

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  
Followers 0

  • Similar Content

    • Nareshm
      By Nareshm
      Hi All,
      I have excel file like this
      and i want to cut cell/text from excel to other software.

       
      I have to cut the cell of B column one by one and past into other software
      If Winexists("No Data Found")
      then restore cuted cell and goto next/down side cell
      How to do it ?
    • Nareshm
      By Nareshm
      Its possible to past previously copied text to somewhere with autoit script ?
      If yes, How it ?
      example : Before I copied ABCD and then copied the PQRS, how to past the previously copied ABCD ?
    • Mag91
      By Mag91
      Hey Community,
      cause im too new in the Auto it world i will try it with the your help. hopefully.
      I woud like to know how i can handle my Problem.
      ----
      I have a Excel Data with 362 random numbers.
      For Example:
      1166642335374 1172899897343
      .....
      this numbers are a part of the filepath ...example
      D:\Projekte\1166_64233_5374
      as u can see its the first number of the Excel data. After the first 4 numbers it shoud make a "_" than another 5 "_"
      This is my first question. How can i handle this to make it Shell execute.
       
      --------
      Second question:
      If i am in the path.
      For Example:
      D:\Projekte\1166_64233_5374
      the code shoud search for specific PDF Files.
      They are named like: 0050569E364B1ED79B900F73E62660EC.pdf
      the first 15 letters are always the same
      0050569E364B1ED
      when he found this data he has to copy it on a Folder on the Desktop.
      (There can also be 2 or 3 pdfs in one Folder with this letters)
      ----
      Please give me some help :-)
       
       
       
       
       
       
    • Mag91
      By Mag91
      Hey Everybody,
      as you know im on a very low autoit-level.
      My question is: How can i read all PDFs from a Folder wich is open and copy them to a Folder on a Desktop.
       
      The Folder wich contains the PDFs is variable Z:\Projektls\"*"*"*EVERYTIME ANOTHER ENDING"*"*"*"*"
      There can be 1 PDF or even 15 PDFs.
      i tried it with _FileListToArray and _FileCopy but i Need some help to understand this language
       
      THANKS!
       
    • MrCheese
      By MrCheese
      Hi,
       
      Wondering what I'm doing wrong.
      as per my script, I activate an external program, copy data from it and I want to paste it into excel, after I clear the current sheet that is there.
      It is some sort of an array as when I manually paste it into excel it expands across rows and down columns (number of which varies).
      This repeats for Xno. of program instances, and consequently I would want it to cycle through x sheets.
      So far I have the following, noting that I dont have the sheet clearing thing detailed yet, but I get the following error: "Error copying cells. @error = 4, @extended = -2147352567"
       
      func Primary() For $i=0 to ubound($term)-1 WinActivate($term[$i]) sleep(500) MouseClick("left",$OptX,$opty) Clipput("") sleep(500) send("!a") sleep(100) Do sleep(100) until Clipget() ;activates sheet no. specified by $i+ 1, removes data from sheet and pastes new data, cycles to the next sheet ;function to clear sheet _Excel_RangeCopyPaste($oWorkbook1.Worksheets($i+1), Default , "A1") If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeCopy Example 2", "Error copying cells." & @CRLF & "@error = " & @error & ", @extended = " & @extended) MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeCopy Example 2", "Range 'A1' from workbook _Excel3.xls successfully copied to 'G15'.") Next EndFunc  
      Any help would be great.