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

    • rudi
      By rudi
      Hello.
      I fail trying to save content from WhatsApp other then plain text to a file that way, that non-char-content will be preserved in it's correct encoding. e.g. Emojis are spoiled.
      I've tried to do so using just filewrite() as well as forcing UTF
      #include <clipboard.au3> MsgBox(0,"Ready to read clipboard","Mark some WhatsApp content with non-char elements, e.g. Emojis, copy that to your clipboard (CTRL+c), then click OK here.") $ClipContent=_ClipBoard_GetData() ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $ClipContent = ' & $ClipContent & @CRLF & '>Error code: ' & @error & @CRLF & "Extended: " & @extended & @CRLF) ;### Debug Console $File="C:\temp\ClipSaveToFile.txt" $h=FileOpen($File,2+8+64) ; overwrite, create path, UTF16 FileWrite($h,$ClipContent) FileClose($h) $h=FileOpen($File,64) $NeuGelesen=FileRead($h) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $NeuGelesen = ' & $NeuGelesen & @CRLF & '>Error code: ' & @error & @CRLF & StringLen ($NeuGelesen) & @CRLF ) ;### Debug Console FileClose($h) _ClipBoard_SetData($NeuGelesen) MsgBox(0,"Done","Re-read content of TEMP file was placed to the clipboard. Now paste this into WhatsApp. (Emojis will be spoiled)") I've also tried other encodings (16, 32, 64, 512)

      Or what is a different, functional approach to save WhatsApp Content to File in a way, to be able to to get it back to post it back to WhatsApp?

      Regards, Rudi.
    • AndreyS
      By AndreyS
      Hello to you, dear developers!
      Could you please tell me if there is an easy way to determine if the information was pasted from the clipboard?
      Without any variation of the insertion via Ctrl+V, or through the context menu.
      I revised the Help and many forum topics, but found nothing suitable.
      Can there be any WinAPI system events that determine this event?
    • czardas
      By czardas
      Haven't had much time to code recently. However the following thread inspired me.
      The debate about linear, parallel and binary search methods was rather interesting and, in an attempt to be diplomatic, I decided to combine @jchd's suggestion with @LarsJ's binary search example. I decided that the binary search algorithm required modification to make it more linear. As usual, 'if you invent something, it probably already exists and if it already exists, it exists for a reason'. My first attempt was not all that good. The code worked but was really a mess. I blame peer pressure (to post an example of a parallel search method).  I will delete that old code in due course.
      With a little memory jogging and a glance at the help file, the solution turned out to be quite easy: I just needed a better understanding of Euler. Further modification will be needed to work with more complicated unicode strings. The output could be returned as an array or a delimitered string. I'm not so interested in those details. I'm just going to post the algorithm for now and anyone, who wants to, can modify it to suit their needs. Both arrays must contain at least 1 element.
      Local $aFoo = [0,1,2,3,4,5,6,7,9,10,11,12,13,14,15,16,19,20,23,24,26,30,35,39,40,41] Local $aBar = [0,1,5,6,7,8,9,10,11,12,13,14,17,18,19,21,24,25,26,27,34,35,38,40] ParallelExponetialSearch($aFoo, $aBar) ; Compares two lists - returning positive matches. Each input array must be unique (individually) and in alphabetical order. Func ParallelExponetialSearch($aFoo, $aBar) Local $sFind, _ $iMin_F = -1, $iMax_F = UBound($aFoo) -1, $Lo_F = $iMin_F, $Hi_F, _ $iMin_B = -1, $iMax_B = UBound($aBar) -1, $Lo_B = $iMin_B, $Hi_B While $iMin_F < $iMax_F And $iMin_B < $iMax_B ; Toggle Arrays - Which array has most untested elements? This is the one we want to search next, ; so we can bypass more comparisons because (in theory) mismatches have a greater chance of being skipped. If $iMax_F - $iMin_F >= $iMax_B - $iMin_B Then ; $aFoo has more (or an equal number of) untested elements $Hi_F = $iMax_F $iMin_B += 1 $sFind = $aBar[$iMin_B] While $Lo_F < $Hi_F ; search $aFoo For $i = 0 To Floor(Log($Hi_F - $Lo_F) / Log(2)) $Lo_F = $iMin_F + 2^$i If $aFoo[$Lo_F] = $sFind Then $iMin_F = $Lo_F ; each match should be added to the output [perhaps an array] ConsoleWrite($sFind & " found at $aFoo[" & $Lo_F & "] = $aBar[" & $iMin_B & "]" & @LF) ExitLoop 2 ElseIf $aFoo[$Lo_F] > $sFind Then $Hi_F = $Lo_F -1 $iMin_F += Floor(2^($i -1)) $Lo_F = $iMin_F ContinueLoop 2 EndIf Next $iMin_F = $Lo_F ; minimum increment is one WEnd Else ; $aBar has more untested elements $Hi_B = $iMax_B $iMin_F += 1 $sFind = $aFoo[$iMin_F] While $Lo_B < $Hi_B ; search $aBar For $i = 0 To Floor(Log($Hi_B - $Lo_B) / Log(2)) $Lo_B = $iMin_B + 2^$i If $aBar[$Lo_B] = $sFind Then $iMin_B = $Lo_B ; each match should be added to the output [perhaps an array] ConsoleWrite($sFind & " found at $aFoo[" & $iMin_F & "] = $aBar[" & $Lo_B & "]" & @LF) ExitLoop 2 ElseIf $aBar[$Lo_B] > $sFind Then $Hi_B = $Lo_B -1 $iMin_B += Floor(2^($i -1)) $Lo_B = $iMin_B ContinueLoop 2 EndIf Next $iMin_B = $Lo_B ; minimum increment is one WEnd EndIf WEnd EndFunc ;==> ParallelExponetialSearch I hope this will be useful to someone. I believe it deserved a thread of its own!
    • 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 ?