Jump to content

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

Link to comment
Share on other sites

  • Moderators

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:

"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 comment
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")
Link to comment
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

Link to comment
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
Link to comment
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

Link to comment
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

Link to comment
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
Link to comment
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

Link to comment
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

Link to comment
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
 Share

×
×
  • Create New...