Jump to content
Sign in to follow this  
Jeanpierre92

Is this possible?

Recommended Posts

Jeanpierre92

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
JLogan3o13

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!

How to get your question answered on this forum!

Share this post


Link to post
Share on other sites
Jeanpierre92

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
Jeanpierre92

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
kylomas

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
Jeanpierre92

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
kylomas

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
kylomas

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
kylomas

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
Jeanpierre92

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
Jeanpierre92

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
BrewManNH

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

    • Epic007
      By Epic007
      Hey guys I'm stuck with a program.....I need a make an automation which copies text from a chat bot app and paste it in notepad to log the replies of my chat bot and to analyse stuff....a lil help pls
       
       
       
       
       
       
       
      Thanks in advance
    • AnonymousX
      By AnonymousX
      Hello,
      I'm trying to write a script that moves copies excel cells into an array. I'll than manipulate the values and send array into another program. 
      I don't want range to be specific to a workbook, or sheet, or set of cells.
      I want user to be able to highlight desired cells and to copy either normally ("Ctrl+C") or by a hotkey ("Alt+C"). 
      Could someone help me with this?
      Thank you,
      I've tried to write the framework: (edited)
      #include <MsgBoxConstants.au3> #include <Array.au3> #include <Excel.au3> HotKeySet("!v", "Pastedata") While True Sleep(1000) WEnd func Makearray() local $bArray ;User has cells already copied ;Convert clipboard into an array ;I don;t know how excel stores data to clipboard so don;t know how to bring it into array _Arraydisplay($bArray) MsgBox(0,0,$bArray) return $bArray endfunc func Pastedata() Local $aArray MsgBox(0,0,"wait",1) ;make array based on assumption user has already copied a range to clipboard $aArray = Makearray() ;paste code ;don;t worry about this I got the rest endfunc  
    • dadalt95
      By dadalt95
      Hi!
      I want to get the signal in this website:
      https://binary-signal.com/pt/chart/eurusd
      I have tried using _IEBodyReadText  and some _StringBetween. What happens is that the text are being update every tick and _IEBodyReadText doesn't.
      To perform the update I used  _IEAction($oIE, "refresh") but it's not good because the website block me after some time due too many requests..
      Is there any other way to get this text every tick?
      PS: The text I want to get is WAIT, CALL or PUT.
       
      Here is the code:
      global $oIE = _IECreate ('https://binary-signal.com/pt/chart/eurusd', 0, 1 , 1 , 0) Local $sText = _IEBodyReadText($oIE) $result = _StringBetween ( $sText , 'PUTEUR/USD on Binary-signal.com', 'sinal está PRONTA') ;MsgBox ( 0, "asf", $result[0]) $espera=StringInStr($result[0], "WAIT") $compra=StringInStr($result[0], "CALL") $venda=StringInStr($result[0], "PUT") ;MsgBox($MB_SYSTEMMODAL, "", $espera) $n=0 $c=0 Captar() Func Captar() ;_IENavigate($oIE, "https://binary-signal.com/pt/chart/eurusd") ;MsgBox($MB_SYSTEMMODAL, "", $n) Local $sText = _IEBodyReadText($oIE) $result = _StringBetween ( $sText , 'PUTEUR/USD on Binary-signal.com', 'sinal está PRONTA') If (Not $compra=0) And $n=0 Then MsgBox($MB_SYSTEMMODAL, "", "COMPRE") $n=1 $c=$c+1 ;_IEAction($oIE, "refresh") Sleep(60000) Captar() ElseIf (Not $venda=0) And $n=0 Then MsgBox($MB_SYSTEMMODAL, "", "VENDA") $c=$c+1 $n=1 ;_IEAction($oIE, "refresh") ;MsgBox($MB_SYSTEMMODAL, "", $n) Sleep(60000) Captar() ElseIf (Not $venda=0) And $n=1 Then ;MsgBox($MB_SYSTEMMODAL, "", "Esperando próxima rodada") $n=1 ;MsgBox($MB_SYSTEMMODAL, "", $n) ;_IEAction($oIE, "refresh") Sleep(60000) Captar() ElseIf (Not $venda=0) And $n=1 Then ;MsgBox($MB_SYSTEMMODAL, "", "Esperando próxima rodada") $n=1 ;MsgBox($MB_SYSTEMMODAL, "", $n) ;_IEAction($oIE, "refresh") Sleep(60000) Captar() Else ;MsgBox("", "", "ESPERE") $n=0 Sleep(1000) ;_IEAction($oIE, "refresh") Local $sText = _IEBodyReadText($oIE) $result = _StringBetween ( $sText , 'PUTEUR/USD on Binary-signal.com', 'sinal está PRONTA') Captar() EndIf EndFunc  
    • AndyS19
      By AndyS19
      I want to copy just the selected text in an input control and put it to the clipboard, but GuiCtrlRead() always reads all of the text in the control.
      In this test code, when I highlight a  portion of the left control's text and press ^C, I want to copy just that text to the clipboard; but when I highlight a  portion of the right control's text and press ^C, I want to copy all of its text to the clipboard.
      #include <Debug.au3> _DebugSetup(@ScriptName & "_debug.txt", False, 2, "") _DebugOut("=============== " & @MON & "/" & @MDAY & "/" & @YEAR & " " & @HOUR & ":" & @MIN & ":" & @SEC & " ====================") #include <GUIConstants.au3> #include <WinAPI.au3> #include <Array.au3> Opt("GUICloseOnESC", 1) ; ESC closes GUI? (0 = no, 1 = yes) Opt("GUIOnEventMode", 1) ; Set OnEvent mode Opt('MustDeclareVars', 1) OnAutoItExitRegister("Event_GUIClose") Opt("GUIEventOptions", 1) ;0=default, 1=just notification, 2=GuiCtrlRead tab index Opt("WinTitleMatchMode", -2) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase Global $hWnd_MainWin, $iID_Left, $iID_Right _Main() Func _Main() $hWnd_MainWin = GUICreate("test7", 200, 300) $iID_Left = GUICtrlCreateInput("AAA BBB CCC (get Selected text)", 10, 30, 200, 25) GUICtrlSetOnEvent($iID_Left, "handle_left_btn") $iID_Right = GUICtrlCreateInput("DDD EEE FFF (get All text)", 10, 60, 200, 25) GUICtrlSetOnEvent($iID_Right, "handle_right_btn") Local $aAccelKeys[1][2] = [["^c", $hWnd_MainWin]] GUISetAccelerators($aAccelKeys) GUISetOnEvent($GUI_EVENT_CLOSE, 'Event_GUIClose') GUISetState() ; Make everything visible While 1 Sleep(127) WEnd EndFunc ;==>_Main Func handle_CTRL_C_key() ConsoleWrite("+++: handle_CTRL_C_key() entered" & @CRLF) Local $hCtrl, $ctrlID, $control_classname, $text $control_classname = ControlGetFocus($hWnd_MainWin) $hCtrl = ControlGetHandle($hWnd_MainWin, "", $control_classname) $ctrlID = _WinAPI_GetDlgCtrlID($hCtrl) If ($ctrlID = $iID_Left) Then $text = GUICtrlRead($ctrlID) ClipPut($text) ConsoleWrite("+++: Copied selected text:" & @CRLF & "==>" & $text & "<==" & @CRLF) ElseIf ($ctrlID = $iID_Right) Then $text = GUICtrlRead($ctrlID) ClipPut($text) ConsoleWrite("+++: Copied all text:" & @CRLF & "==>" & $text & "<==" & @CRLF) EndIf EndFunc ;==>handle_CTRL_C_key Func Event_GUIClose() Exit (99) EndFunc ;==>Event_GUIClose Func handle_left_btn() ConsoleWrite("+++: handle_left_btn() entered" & @CRLF) EndFunc ;==>handle_left_btn Func handle_right_btn() ConsoleWrite("+++: handle_right_btn() entered" & @CRLF) EndFunc ;==>handle_right_btn
       
×