 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
a.antonio Guest
|
Posted: Wed Aug 13, 2008 2:44 pm Post subject: Global string deletion |
|
|
Lets have the script line:
My question is simple:
is there any way to delete this entry from the text box by a single 'Undo' [global] command - like a 'Paste' command would allow - instead of having to type 10 times ^Z?
antonio |
|
| Back to top |
|
 |
Serenity
Joined: 07 Nov 2004 Posts: 1276
|
Posted: Wed Aug 13, 2008 3:13 pm Post subject: |
|
|
You can use the built-in variable A_PriorHotkey to get the hotstring label, and have Ctrl+Z send backspace to delete it, eg:
| Code: | ::btw:: ; A_PriorHotkey = ::btw
send, by the way
return
; ::btw::by the way ; A_PriorHotkey is blank :(
$^z::
if A_PriorHotkey = ::btw
send {backspace 10}
else
send ^z
return |
_________________ "Anything worth doing is worth doing slowly." - Mae West
 |
|
| Back to top |
|
 |
a.antonio Guest
|
Posted: Wed Aug 13, 2008 3:49 pm Post subject: Global string deletion |
|
|
Thank you Serenity,
but this seems a bit complicated to apply to hundreds of [different in lenght] strings
so I tried this way, that seems quicker
and does not need to scan each character:
I put the string into the clipboard and then use ^v,
| Code: | ::ww::
clipboard = by the way
Send ^v
return |
but this too must be done somehow for every string.
I was asking for a general purpose setting mode/parameter
in order to paste the whole streams as if they came from the clipboard.
(some utilities I have used give this choice)
antonio |
|
| Back to top |
|
 |
Serenity
Joined: 07 Nov 2004 Posts: 1276
|
Posted: Wed Aug 13, 2008 4:01 pm Post subject: |
|
|
Yes, I thought it would be a bit much if you had lots of hotstrings. It would be nice if there were built-in variables for the hotstring so then Ctrl+Z could just be something like:
| Code: | ^z::
loop % StrLen(A_PriorHotString)
Send {backspace}
return |
Maybe something for the wish list? _________________ "Anything worth doing is worth doing slowly." - Mae West
 |
|
| Back to top |
|
 |
Dra_Gon
Joined: 25 May 2007 Posts: 314
|
Posted: Wed Aug 13, 2008 7:33 pm Post subject: |
|
|
How about something like this:
| Code: |
::btw::
clipboard = by the way
My_HSLen := StrLen(clipboard)
return
^z::
loop % My_HSLen
Send {backspace}
My_HSLen = 0
return
|
The "My_HSLen := StrLen(clipboard)" can easily be added to all of your hotstrings without having to adjust it for each one and the "My_HSLen = 0" reduces it back to zero so you won't backspace if you accidentally hit Ctrl+Z {I'd actually use the Win [#] instead of Ctrl since most Applications I've come across use Ctrl+Z for undo}.
Hope this helps.
Ciao,
Dra'Gon _________________
For a good laugh {hopefully} >> megamatts.50megs.com
My WritersCafe profile>>
http://www.writerscafe.org/writers/BlueDragonFire/ |
|
| Back to top |
|
 |
a.antonio Guest
|
Posted: Thu Aug 14, 2008 6:51 pm Post subject: Global string deletion |
|
|
Yes, this can be considered somehow a step forward.
However the substantial problem in my view remains, in that each byte must be backspaced, i.e. deleted, not undone.
This slows and can get confused with longer strings, but above all it will add a lot of undo steps to the stack of any Undo command, as is into most editors.
The best mode would be to give the choice - once processed the line with its parameters, clipboard included - if to send the string to the keyboard buffer or to the clipboard.
In the 2nd case the previous clipboard content can be stored into a variable, the clipboard filled by the string to be pasted thereafter, leaving the user free to undo it by a single keystroke in any moment; then restore to the clipboard the temporary variable's value; and that's all.
This process is immediate and prevents any other routine (eg. popups) to interfere with unpredictable consequences, depending on the length( ) and the kind of the characters involved.
For a daily example in my Hyphenator-pro project, the RichEdit text editor can handle hundreds of Undo commands, that can apply both to the single byte and to the whole string, according to the real-time setting by the user (see: www.hyphenator.com, you can get it free on request).
I think it could be awful having to cancel and rewrite several HTML command lines together (sent by single bytes), to simply adjust some Tables' setup; but probably we remained very few guys to do such things
I believe that an application of the AutoHotKey's level - the best I've met - should include that option.
Ciao Dra'Gon.
a.antonio |
|
| Back to top |
|
 |
a.antonio Guest
|
Posted: Thu Aug 14, 2008 7:09 pm Post subject: Global string deletion |
|
|
Perhaps I was not clear enough (and I'm sorry for my limited English ).
The choice I'm talking about, though available for single lines, should be set at a main level, like an #IfClipbActive or similar command (I don't yet know all them!), so that a defined list of lines can be processed this way. This should simplify a lot.
a.antonio
p.s. - About my link above, a comma was embedded causing an error; should you wish to visit it, please, use the IExplorer (v.6) just for a while! thanks. |
|
| Back to top |
|
 |
Sivvy
Joined: 21 Jul 2008 Posts: 711 Location: Calgary, AB, Canada
|
Posted: Thu Aug 14, 2008 7:34 pm Post subject: |
|
|
| Quote: | | However the substantial problem in my view remains, in that each byte must be backspaced, i.e. deleted, not undone |
Did you notice that they both created a hotkey CTRL-z, and that they aren't using the real CTRL-z windows hotkey? It won't be undone, it will be backspaced.
If it makes more sense to you:
| Code: | ::btw::
clipboard = by the way
My_HSLen := StrLen(clipboard)
return
^q::
loop % My_HSLen
Send {backspace}
My_HSLen = 0
return |
Now it's CTRL-q doing it. CTRL-z has been taken out of the equation, and nothing is being "Undone"... Only deleted. |
|
| Back to top |
|
 |
a.antonio Guest
|
Posted: Fri Aug 15, 2008 11:00 am Post subject: Global string deletion |
|
|
Right! whenever you entitle a routine to be called with a ^z - that is intended by all environment as the Undo command - the one should match the other, therefore the use of the backspace value inside should be considered improper; so it might be due to have taken CTRL-z out.
I'm sorry , Unfortunately I must write in a not native language, while this subject is enlarging more and more.
I had to write: | Quote: | | :" in that each byte [in your routines] must be backspaced, i.e. deleted not undone" |
Briefly: the fact that the characters are backspaced this is the problem. I don't want characters to be separately Deleted (as is in the answers), I need to Undo, I mean the "true Undo" function.
Well I'll try to tell it again and better.
Whether we use the ^z or ^q of your samples, the problem I pointed out is that one byte at a time it is going to be removed, not the whole string insertion undone. Beyond some effects mentioned already, like saturating or overlapping a normal Undo stack, this may introduce various problems.
All the routines above behave as expected if they are called just after typing their related hotkeys, but ask yourself what happens if you don't call any, but need to Undo a portion of the text insertion after a while, i.e. after other text or hotkeys were entered (this does not arise of course with CTRL-q, that reduces the function to a single, immediate attempt; so it does not satisfy the initial question, and can be in itself of very low utility).
As to the CTRL-z, only the last ^z loop will remain in action, exactly as it was defined.
This means that since the last "by the way" up to the current keystroke the first ^z that you need to type will erase the last 10 characters!
Moreover, being this deletion a keyboard entry (in place of an Undo action), all these actions will be acquired by the Undo command itself like entries to be undone in turn, instead of undone actions to be removed then from the stack; should I add that this does not allow any Redo command?
If I explained it right, I don't find all that so much helpful for any current job.
a.antonio |
|
| Back to top |
|
 |
Serenity
Joined: 07 Nov 2004 Posts: 1276
|
Posted: Fri Aug 15, 2008 11:31 am Post subject: Re: Global string deletion |
|
|
| a.antonio wrote: | | Briefly: the fact that the characters are backspaced this is the problem. I don't want characters to be separately Deleted (as is in the answers), I need to Undo, I mean the "true Undo" function. |
I wonder if there is a way to modify the Edit control's undo buffer, perhaps with DllCall/WriteProcessMemory, so that it thinks to undo ten spaces instead of one. _________________ "Anything worth doing is worth doing slowly." - Mae West
 |
|
| Back to top |
|
 |
Sivvy
Joined: 21 Jul 2008 Posts: 711 Location: Calgary, AB, Canada
|
Posted: Fri Aug 15, 2008 2:55 pm Post subject: |
|
|
Would this work for you?
| Code: | SetTitleMatchMode, 2
::btw::
HotStringText = By The Way
SendInput, %HotStringText%
HotStringTextLength := StrLen(HotStringText)
Return
^q::
ControlGetText, AllText, , Notepad
StringTrimRight, KeptText, AllText, %HotStringTextLength%
ControlSetText, , %KeptText%, Notepad
Return |
|
|
| Back to top |
|
 |
HugoV
Joined: 27 May 2007 Posts: 650
|
Posted: Fri Aug 15, 2008 3:16 pm Post subject: |
|
|
mmm I haven't read the posts to closely but | Code: | ::btw::
SendPaste("By the way") ; call function with text to paste in qoutes
Return
SendPaste(Text)
{
ClipSaved := ClipboardAll ; Save the entire clipboard to a variable of your choice.
Clipboard =
Clipboard := Text
Send, {Ctrl down}v{Ctrl up} ; paste
Clipboard := ClipSaved ; Restore the original clipboard. Note the use of Clipboard (not ClipboardAll).
ClipSaved = ; Free the memory in case the clipboard was very large.
} | will allow you to undo with CTRL-Z because it undoes the paste operation, _________________ When parsing a CSV file use Loop, parse, Inputvar, CSV! |
|
| Back to top |
|
 |
Guest
|
Posted: Fri Aug 15, 2008 3:31 pm Post subject: Re: Global string deletion |
|
|
| Serenity wrote: |
I wonder if there is a way to modify the Edit control's undo buffer, perhaps with DllCall/WriteProcessMemory, so that it thinks to undo ten spaces instead of one. |
Do you mean with single distinctions for all the entered hotkeys in sequence?
Is there any true need to strive to modify it, in order to reach nothing more than its normal job?
would'nt it be enough (and quite simple) to paste all strings as required by a meta command?
___________
Perhaps a Function (or Gosub?) could be set, to reduce again the syntax that I am using to just a single word and line, with no need of a return then.
eg.
| Code: | F10::
clipboard = trace(2)`n
Send ^v
return |
could be reduced to something like:
| Code: | | F10:: Clipx trace(2)`n |
with the effect of a Send command, but packing the whole string block.
Can your experience help?
a.antonio
"Anything worth doing is worth doing slowly."
Think this applies to the computer processors too?  |
|
| Back to top |
|
 |
HugoV
Joined: 27 May 2007 Posts: 650
|
Posted: Fri Aug 15, 2008 4:00 pm Post subject: Re: Global string deletion |
|
|
| Anonymous wrote: | | Perhaps a Function (or Gosub?) could be set, to reduce again the syntax that I am using to just a single word and line, with no need of a return then. | That works for hotkeys not for abbreviations, add F10::SendPaste("By the way") to the example above and see the difference. for the btw you need the return as shown in the script. Did you try it? _________________ When parsing a CSV file use Loop, parse, Inputvar, CSV! |
|
| Back to top |
|
 |
a.antonio Guest
|
Posted: Fri Aug 15, 2008 4:26 pm Post subject: Re: Global string deletion |
|
|
Hi Sivvy and HugoV,
thanks for your solutions too;
as you can see above, my purpose was to reduce to one single line a 4-lines command - very efficient so far - that should be repeated for hundreds of lines.
The Sivvy's code works once more on single bytes, and that's not what was asked; it has also the limit that when the string is undone, the hotstring appears again and needs to be undone too.
The HugoV's Function can be called for most cases, reducing to a single parameter-line its job, therefore it seems to match my request.
One limitation that I see is that if the Text is handled as is; i.e. if the string to be pasted includes the current clipboard content, this is not accomplished yet; I have not enough knowledge (and time) for this enhancement, but for such few cases the Send mode works good.
So thanks again.
| HugoV wrote: | | Anonymous wrote: | | Perhaps a Function (or Gosub?) could be set, to reduce again the syntax that I am using to just a single word and line, with no need of a return then. | That works for hotkeys not for abbreviations, add F10::SendPaste("By the way") to the example above and see the difference. for the btw you need the return as shown in the script. Did you try it? |
While you were writing this last I was trying the 1st; now I'm going to verify that difference you say.
a.antonio |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|