AutoHotkey Community

It is currently May 27th, 2012, 12:42 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 21 posts ]  Go to page Previous  1, 2
Author Message
 Post subject:
PostPosted: December 3rd, 2010, 1:06 pm 
This is where I'm at..

Pressing F1 returns the number of lines ( used for a quick check )
Pressing F2 deletes the first line..

Once the first line has been deleted, I need the cursor on a new line after the very last line... ( does that make sense )

How do I do that ? thanks :)

Code:
#include Edit.ahk
#include Edit_DeleteLine.ahk
#include Edit_SelectLine.ahk
Menu, FileMenu, Add, Exit, Exit
Menu, HelpMenu, Add, Help, Help

Menu, MyMenuBar, Add, &File, :FileMenu
Menu, MyMenuBar, Add, &Help, :HelpMenu

Gui, Menu, MyMenuBar
Gui, Add, Edit, w175 h175 hwndLogHwnd, ABABABABABABABAB`r`123451234512345`r`n999999999999999`r`nZZZZZZZZZZZZZZZZZZZZ
Gui, Show,w200 H200,
return

Exit:
Help:
exitapp
return

F1::
len:=Edit_GetLineCount(LogHwnd)
msgbox %len%
return

F2::
Edit_DeleteLine(LogHwnd,p_LineIdx=0)
return


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: December 3rd, 2010, 10:43 pm 
Offline

Joined: October 1st, 2005, 9:55 pm
Posts: 775
Location: Texas, USA
You're on the right track tov. Just use the Edit_SetSel function to move the cursor to the bottom. I've modified your example to fit the bill but you get the idea.

Code:
#include Edit.ahk
#include Edit_DeleteLine.ahk
#include Edit_SelectLine.ahk
Menu, FileMenu, Add, Exit, Exit
Menu, HelpMenu, Add, Help, Help

Menu, MyMenuBar, Add, &File, :FileMenu
Menu, MyMenuBar, Add, &Help, :HelpMenu

Gui, Menu, MyMenuBar
Gui, Add, Edit, w175 h175 hwndLogHwnd, ABABABABABABABAB`r`n123451234512345`r`n999999999999999`r`nZZZZZZZZZZZZZZZZZZZZ`r`n
Gui, Show,w200 H200,
return

Exit:
Help:
GUIEscape:
GUIClose:
exitapp
return

F1::
len:=Edit_GetLineCount(LogHwnd)
msgbox %len%
return

F2::
Edit_DeleteLine(LogHwnd,p_LineIdx=0)
TL:=Edit_GetTextLength(LogHwnd)
Edit_SetSel(LogHwnd,TL,TL)
Edit_ScrollCaret(LogHwnd)   ;-- This makes sure the last line can be seen
return

Good luck!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 4th, 2010, 10:46 pm 
Cheers
I'll try this in the morning..

Should this work OK with a GUI Edit that is constantly being updated from a live stream (using editpaste)

My aim is to try an limit the 'edit' to approx 5000 lines and then as new lines are added, old ones are deleted... obviously the edit needs to have scrolled to the bottom so it's acting as an effective 'tail' for a live tcp stream.

Thanks :)


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: April 7th, 2011, 8:28 am 
Offline

Joined: September 15th, 2006, 10:25 am
Posts: 567
This is a wonderful library!! Thanks for your hard work :)

_________________
If i've seen further it is by standing on the shoulders of giants

my site | ~shajul | WYSIWYG BBCode Editor


Report this post
Top
 Profile  
Reply with quote  
PostPosted: May 31st, 2011, 4:09 am 
Offline

Joined: October 1st, 2005, 9:55 pm
Posts: 775
Location: Texas, USA
No Dialog Find, Find Previous, Find Next, and Replace

I download therefore I rename.

I'm forever making minor name changes to the files that I download from the interwebs. Usually, I need to replace several "_" or "." characters. Many times the title is all upper/lower case and I want to capitalize the title.

A rename program for one file is overkill so I was looking for something else to help me quickly make minor changes to a single file name. I noticed that when making changes to a file in Windows Explorer, an Edit control is shown so I thought, "The Edit Library would be perfect for this!"

When making changes to a file name in Windows Explorer, the Edit control shown is a self-contained dialog. If any other windows or dialogs are shown, the Edit control is hidden/closed. Adding a dialog to enter Find and Replace information is out of the question. A "No Dialog" Find/Replace command is what is needed.

This script provide the following no-dialog commands:
  • Find (Ctrl+Win+Alt+F). To use:
    • Press hotkey.
    • Enter search text. Press Enter to start the search.
    A few notes:
    • The search text is not displayed (echoed) as you are typing so enter carefully. The Backspace key can be used to erase incorrect characters.
    • The search text is not case sensitive.
    • Use the Escape key to abort at any time.
  • Find Next (Ctrl+Win+Alt+F3) and Find Previous (Ctrl+Win+Alt+F2). These commands use the last search string entered by the Find command.
  • Replace (Ctrl+Win+Alt+H). To use:
    • Select working text. This step will limit the Replace command to only the text that is selected.
    • Press hotkey.
    • Enter the search and replace text. The Enter key indicates the end of input. Press Enter at the end of the search text and at the end the replace text.
    A few notes:
    • The search/replace text is not displayed (echoed) as you are typing so enter carefully. The Backspace key can be used to erase incorrect characters.
    • The search text is not case sensitive but the replace text is used as typed.
    • Use the Escape key to abort at any time.
    • If needed, use Undo (Ctrl+Z) to reverse the change.
    • By design, this is a "Replace All" command. If you only want to replace a specific number of occurrences of the search string, be sure to only select the desired target text. For example, to replace all "." characters in a file name, select all but the last node of the file (Ex: Select everything except the ".pdf" at the end).
    For example, to replace "red" with "blue" (sans quotes), do the following:
    • Select the text that includes the "red" string.
    • Press the Replace hotkey: Ctrl+Win+Alt+H
    • Type the following: red{Enter}blue{Enter}
    • If needed, use Undo (Ctrl+Z) to reverse the change.
  • Convert Case. The following commands are available (select the desired text before using):
    • Lowercase (Ctrl+Win+Alt+L).
    • Uppercase (Ctrl+Win+Alt+U).
    • Capitalize (Ctrl+Win+Alt+C). I use this one a lot.
    • Toggle case (Ctrl+Win+Alt+T).
Here's the code (needs the Edit Library of course):
Code:
;[================]
;[  Convert Case  ]
;[================]
^#!c::  ;-- Capitalize
^#!l::  ;-- Lowercase
^#!t::  ;-- Toggle case
^#!u::  ;-- Uppercase

;-- Bounce if an Edit control is not active
if not Edit_GetActiveHandles(hEdit,hWindow,True)
    return

;-- Convert
Edit_ConvertCase(hEdit,SubStr(A_ThisHotKey,0))
return


;[===============]
;[      Find     ]
;[  (No Dialog)  ]
;[===============]
^#!f::
NoDialogFind:
;-- Bounce if an Edit control is not active
if not Edit_GetActiveHandles(hEdit,hWindow,True)
    return

;-- Collect FindWhat string
Input $FindWhat,T9,{Enter}{Escape}
if (ErrorLevel<>"EndKey:Enter") or StrLen($FindWhat)=0
    {
    SoundPlay *16 ;-- Error
    return
    }

;-- Set $FindFlags
$FindFlags:="d"

;-- Find it
NoDialogFind_Part2:  ;-- Used by the Find Previous and Find Next shortcuts

;-- Collect current positions
Edit_GetSel(hEdit,$StartSelPos,$EndSelPos)

;-- Which direction?
if $FindFlags Contains d
    $FindPos:=Edit_FindText(hEdit,$FindWhat,$EndSelPos,-1)
 else
    $FindPos:=Edit_FindText(hEdit,$FindWhat,$StartSelPos,0)

;-- Not found?
if ($FindPos=-1)
    {
    SoundPlay *-1  ;-- Default beep
    return
    }

;-- Select it
Edit_SetSel(hEdit,$FindPos,$FindPos+StrLen($FindWhat))

;-- Make sure caret is showing
Edit_ScrollCaret(hEdit)
return


;[=================]
;[  Find Previous  ]
;[   (No Dialog)   ]
;[=================]
^#!F2::
NoDialogFindPrevious:
;-- Bounce if an Edit control is not active
if not Edit_GetActiveHandles(hEdit,hWindow,True)
    return

;-- Bounce if Find was never called
if StrLen($FindWhat)=0
    return

;-- Set $FindFlags
$FindFlags:=""

;-- Find it
gosub NoDialogFind_Part2
return


;[===============]
;[   Find Next   ]
;[  (No Dialog)  ]
;[===============]
^#!F3::
NoDialogFindNext:
;-- Bounce if an Edit control is not active
if not Edit_GetActiveHandles(hEdit,hWindow,True)
    return

;-- Bounce if Find was never called
if StrLen($FindWhat)=0
    return

;-- Set $FindFlags
$FindFlags:="d"

;-- Find it
gosub NoDialogFind_Part2
return


;[===============]
;[    Replace    ]
;[  (No Dialog)  ]
;[===============]
^#!h::
NoDialogReplace:
;-- Bounce if an Edit control is not active
if not Edit_GetActiveHandles(hEdit,hWindow,True)
    return

;-- Collect current select postions
Edit_GetSel(hEdit,$StartSelPos,$EndSelPos)
if ($StartSelPos=$EndSelPos)  ;-- Nothing selected
    {
    SoundPlay *16 ;-- Error
    return
    }

;-- Collect FindWhat string
Input $FindWhat,T9,{Enter}{Escape}
if (ErrorLevel<>"EndKey:Enter") or StrLen($FindWhat)=0
    {
    SoundPlay *16 ;-- Error
    return
    }

;-- Collect ReplaceWith string
Input $ReplaceWith,T9,{Enter}{Escape}
if ErrorLevel in EndKey:Escape,Timeout
    {
    SoundPlay *16 ;-- Error
    return
    }

;-- Collect selected text
$SelectedText:=Edit_GetSelText(hEdit)

;-- Replace All
StringReplace $SelectedText,$SelectedText,%$FindWhat%,%$ReplaceWith%,All

;-- Replace selected text with converted text
Edit_ReplaceSel(hEdit,$SelectedText)

;-- Reselect
Edit_SetSel(hEdit,$StartSelPos,$StartSelPos+StrLen($SelectedText))
return


A couple of final thoughts...
  • Although the Find and Replace commands were originally designed for a single-line Edit control, they will work on any edit control.
  • This script is just an example. Please feel free to make any changes you want.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 22nd, 2011, 12:36 am 
Offline

Joined: October 1st, 2005, 9:55 pm
Posts: 775
Location: Texas, USA
Validate As You Type

The idea for this example was gleaned from an script published by jsherk. Thanks! The original post can be found here.

Real-Time Validation/Auto-Correct probably shouldn't be used on most Edit control objects but I'm sure there a few places where this little gem can provide real value. The concept is fairly simple: Stop the user from entering invalid characters as they are typing.

Here's the example script (needs the Edit Library of course):

Code:
;-- Thanks to jsherk for the idea for this example
;   Post: http://www.autohotkey.com/forum/viewtopic.php?t=73246

;[===============]
;[  Environment  ]
;[===============]
#NoEnv
#SingleInstance Force
ListLines Off

;[=============]
;[  Build GUI  ]
;[=============]
gui -MinimizeBox
gui Add,Text,,Example 1: File name.`nAll characters allowed except for the following: \ / : * ? < > |
gui Add,Edit,w500 hWndhEdit1 gEdit1
gui Add,Text ;-- Spacer
gui Add,Text,,Example 2: Number (0-9) characters only.  Maximum of 10 digits.`nExample of use: American telephone number.
gui Add,Edit,w120 hWndhEdit2 gEdit2 Number
    ;-- Note 1: Although not really needed, the "Number" option is included here
    ;   because it provides standard and familiar feedback to the user when
    ;   non-number characters are entered via the keyboard.
    ;
    ;-- Note 2: The "Limit" option is not used here because when pasting, the
    ;   option may truncate the value before the script has a chance to remove
    ;   any invalid characters.  For example, the "Limit10" option would
    ;   truncate the value of "(403) 555-1212" to "(403) 555-" before the script
    ;   has a chance to remove all non-Number characters.  The end result would
    ;   be "403555". Without the "Limit10" option, all 10 number characters are
    ;   preserved and the end result is "4035551212".

gui Add,Text ;-- Spacer
gui Add,Text,,Example 3: Hexadecimal (0-9, A-F) characters only.  Maximum of 16 digits/characters.`nExample of use: 64-bit hex value.
gui Add,Edit,w200 hWndhEdit3 gEdit3 Uppercase
    ;-- Note: The "Uppercase" option is used to keep the any hex letters
    ;   consistently one case (Uppercase).  "Lowercase" can be used instead.

gui Show,,Validate As You Type - Examples
return

GUIEscape:
GuiClose:
ExitApp


;[============]
;[  Validate  ]
;[============]
Edit1:
Text:=Edit_GetText(hEdit1)
NewText:= RegExReplace(Text,"[\\/:*?<>|]","")
    ;-- Allow everything except for the following: \ / : * ? < > |

if (NewText<>Text)
    {
    Edit_GetSel(hEdit1,StartSelPos,EndSelPos)    ;-- Get caret position
    Edit_SetText(hEdit1,NewText)                 ;-- Replace text.
        ;-- Note: The Undo buffer is automatically flushed after this command is
        ;   executed.  This is not a bad thing.  Undo is not desired if the user
        ;   entered or pasted invalid characters.

    NewSelPos:=EndSelPos-(StrLen(Text)-StrLen(NewText))
    Edit_SetSel(hEdit1,NewSelPos,NewSelPos)      ;-- Reposition caret
    SoundPlay *-1  ;-- Default system beep
        ;-- Note: The sound is both informative and behavioral.  It informs the
        ;   user that an invalid character has been entered and, after a while,
        ;   it encourages the user to refrain from entering invalid characters
        ;   in the future.  When pasting text that include one or more invalid
        ;   characters, this sound may be the only indicator that not all
        ;   characters from the clipboard made it to the Edit field.
    }

return


Edit2:
Text:=Edit_GetText(hEdit2)
NewText:=SubStr(RegExReplace(Text,"[^0-9]",""),1,10)
    ;-- Unsigned integer only.  Max of 10 digits.

if (NewText<>Text)
    {
    Edit_GetSel(hEdit2,StartSelPos,EndSelPos)    ;-- Get caret position
    Edit_SetText(hEdit2,NewText)                 ;-- Replace text.
    NewSelPos:=EndSelPos-(StrLen(Text)-StrLen(NewText))
    Edit_SetSel(hEdit2,NewSelPos,NewSelPos)      ;-- Reposition caret
    SoundPlay *-1  ;-- Default system beep
    }

return


Edit3:
Text:=Edit_GetText(hEdit3)
NewText:=SubStr(RegExReplace(Text,"[^0-9A-F]",""),1,16)
    ;-- Hex characters only.  Max of 16 characters.

if (NewText<>Text)
    {
    Edit_GetSel(hEdit3,StartSelPos,EndSelPos)    ;-- Get caret position
    Edit_SetText(hEdit3,NewText)                 ;-- Replace text.
    NewSelPos:=EndSelPos-(StrLen(Text)-StrLen(NewText))
    Edit_SetSel(hEdit3,NewSelPos,NewSelPos)      ;-- Reposition caret
    SoundPlay *-1  ;-- Default system beep
    }

return

#include Edit.ahk


A few final thoughts...
  • For most applications, these examples represent a non-standard method of data validation. Use with discretion.
  • Although this method of validation will work on any edit control, it works best on short, single-line edit controls.
  • I hope that someone finds this useful.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 21 posts ]  Go to page Previous  1, 2

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bon, Google Feedfetcher, maul.esel and 16 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group