tsolrm Posted March 18, 2011 Posted March 18, 2011 Hi guys I've got a problem Func AddText10() Send("^c") $SelectedText = ClipGet() $Replace="" $SelectedText=StringReplace($SelectedText, ' ',$Replace) $hFile = FileOpen("BanList.txt", 1) FileWriteLine($hFile, $slash&$banstring&" "&$SelectedText&" 10") FileClose($hFile) EndFunc My idea is that the person using the program should select a word and then press "1" and then a line "/ban word 10" should appear in banlist.txt So here when 1 is pressed it sends ctrl+c and stuff gets put on clipboard. this works on Windows 7 if run as an administrator but doesn't work on XP? Can anyone please give some advice on how to solve this problem or maybe achieve the same result using a different method? Also Although I've specified "/" as Ascii code, if a russian keyboard is turned on instead of english it just writes "|" instead. Anyway to solve this problem? $slash= Chr ( 47 ) $banstring=String("ban") FileWriteLine($hFile, $slash&$banstring&" "&$SelectedText&" 10") so this comes out as |ban word 10 instead of /ban word 10 Any help would be appreciated - thanks!
saywell Posted March 18, 2011 Posted March 18, 2011 Put some error checking in to find out where things are going wrong. msgbox or consolewrite after the clipget, to check it's copying. Same after your white space strip [ have you seen StringStripWS btw?]. Also, is the file opening? Do you need the full path here? Chech with If $file = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf after the fileopen command. Much of what I've learned over the last year or so is accompanied by commented-out msgboxes, arraydisplays etc where I've done some trial and error work! William
tsolrm Posted March 18, 2011 Author Posted March 18, 2011 From what i understood Send("^c") doesn't work on XP. Is there any other way to put the selected text on clipboard?
saywell Posted March 18, 2011 Posted March 18, 2011 (edited) Send("^{c}") works on XP where I am. But it seems you need to send an esc after - don't know why! ClipPut("") WinActivate ("[CLASS:Notepad]", "") WinWaitActive("[CLASS:Notepad]", "") Send("^{c}") Send("{ESC}") $filename = ClipGet() MsgBox(0, "", $filename) Exit William Edited March 18, 2011 by saywell
GEOSoft Posted March 18, 2011 Posted March 18, 2011 (edited) You should have also posted the part of your code where you set the hotkey so we could see if something was wrong there. This seems to work fine for me. HotKeySet("{1}", "AddText10") HotKeySet("{Esc}", "_Quit") While 1 Sleep(5) WEnd Func AddText10() HotKeySet("{1}") Send("^c") $SelectedText = ClipGet() $Replace="" $SelectedText=StringReplace($SelectedText, ' ',$Replace) $hFile = FileOpen("BanList.txt", 1) FileWriteLine($hFile, $slash&$banstring&" "&$SelectedText&" 10") FileClose($hFile) HotKeySet("1", "addText10") EndFunc Func _Quit() HotKeySet("{1}") ;; These HotKeySet() Lines are for safety only HotKeySet("{Esc}") Exit EndFuncAre you sure you used some method to keep the script running until you wanted to close it. I used the While 1 loop to do that. EDIT: Minor code change for consistency. Edited March 18, 2011 by GEOSoft George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!"
tsolrm Posted March 18, 2011 Author Posted March 18, 2011 Thanks for your replies guys My script for Send("^c") works perfectly on windows 7, but on XP for some reason it doesn't. I will try using Send("^{c}") in the mean time and see what happens. Could anyone else suggest a different method how i could copy selected text to clipboard?
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now