Sign in to follow this  
Followers 0
charvi

Toggle Insert / Overwrite

10 posts in this topic

How do I toggle keyboard Insert and Overwrite modes?

I tried the below code with no success. It always inserts characters.

Send ("{Ins}")

The Help seems not to provide an {Overwrite} option.... ?

Share this post


Link to post
Share on other sites



This will depend on the program having the forum supporting the Insert/Overwrite toggle, but when I run this script from SciTE I do see the INS go to OVR in the left bottom corner

send("{INS}")
sleep(2000)
send("{INS}")

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

This will depend on the program having the forum supporting the Insert/Overwrite toggle, but when I run this script from SciTE I do see the INS go to OVR in the left bottom corner

send("{INS}")
sleep(2000)
send("{INS}")
Jos,

Indeed, your example works fine, but it does not work in my script, where I would like to place the caret at the fifth position, then prompt for a number that will replace the 123-456 in the example below. Even manually hitting the Insert key seems to have no effect! (strange...)

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <WinAPI.au3>


$hWnd = GUICreate("Input with caret at desired position", 350, 130)
GUISetFont(14, 400, 1, "DOSLike")

$btnOK = GUICtrlCreateButton("&OK", 218, 70, 80, 30, 0)
GUICtrlCreateLabel("Number: ", 20, 24, 200, 20)
$input1 = GUICtrlCreateInput("555-123-456", 100, 22, 200, 24)

GUISetState()
GUICtrlSetState($input1, $GUI_FOCUS)
Send("{Home}{Right}{Right}{Right}{Right}{Ins}")

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case -3, $GUI_EVENT_CLOSE, $btnOK
            Exit
    EndSwitch
WEnd

Share this post


Link to post
Share on other sites

Why not set the hyphens (-) as labels and use three separate input boxes for each set of digits? Text in the input boxes should highlight when they are selected and be automatically overwritten by user input.

Also, keep in mind that "DOSLike" is not a standard Windows font.

Thanubis,

Your idea is excellent (and approved!), but my code was just an imagined example for the Toggle Insert/Overwrite problem.

That's right, DOSLike is not a standard font, and I forgot to remove it when I posted it here. Anyway, if you do not have that font, it will be ignored and I believe that "MS Sans Serif" will be used instead, which does not affect the Toggle problem (which is at this time not yet solved...).

Share this post


Link to post
Share on other sites

Oh yeah, I forgot to mention that as far as I know, Insert/Overwrite will not work for input boxes, no matter how they are made.

I did a brief test with various programs and the "Ins" key did nothing for input boxes created with AutoIt, Delphi, or C++.

There may be some code you can add to a program to allow toggling of the insert key in an input box, but that's far beyond my current abilities, assuming it's even possible.

Fascinating... You are right, I could not toggle in any program except in Word, Excel, the Command Prompt and.... the SciTE Editor!!!

Perhaps this might be possible with a DLL call, but this is beyond my knowledge too.

Tomorrow I will post in this forum an input editor I was trying to write in January, but gave up because of typing speed problems. If anyone is interested, please watch for the title 'DOS alike Input Editor' :)

Share this post


Link to post
Share on other sites

Well, i think it's window's limitation, but we always(?) can work it around :)

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GUIEdit.au3>
;

Global $iIns_Is_ON = False

$hWnd = GUICreate("Input with caret at desired position", 350, 130)
GUISetFont(14, 400, 1, "DOSLike")

GUICtrlCreateLabel("Number: ", 20, 25, 70, 20)
$Input1 = GUICtrlCreateInput("555-123-456", 100, 20, 200, 25)

$btnOK = GUICtrlCreateButton("&OK", 220, 70, 80, 30, 0)
$btnToggleIns = GUICtrlCreateButton("Toggle INS", 100, 70, 100, 30, 0)

GUISetState()
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE, $btnOK
            Exit
        Case $btnToggleIns
            $iIns_Is_ON = Not $iIns_Is_ON
            GUICtrlSetState($Input1, $GUI_FOCUS)
            _GUICtrlEdit_SetSel($Input1, 0, 0)
    EndSwitch
WEnd

Func WM_COMMAND($hWnd, $msg, $wParam, $lParam)
    Local $nNotifyCode = BitShift($wParam, 16)
    Local $nID = BitAND($wParam, 0xFFFF)
    Local $hCtrl = $lParam
    
    Switch $nID
        Case $Input1
            Switch $nNotifyCode
                Case $EN_CHANGE;, $EN_UPDATE
                    If Not $iIns_Is_ON Then Return $GUI_RUNDEFMSG
                    
                    Local $aSelection = _GUICtrlEdit_GetSel($Input1)
                    Local $sInput_Data = GUICtrlRead($Input1)
                    
                    If $aSelection[0] <> $aSelection[1] Then Return $GUI_RUNDEFMSG
                    
                    GUICtrlSetData($Input1, StringLeft($sInput_Data, $aSelection[0]) & StringMid($sInput_Data, $aSelection[0]+2))
                    _GUICtrlEdit_SetSel($Input1, $aSelection[0], $aSelection[0])
            EndSwitch
    EndSwitch
    
    Return $GUI_RUNDEFMSG
EndFunc

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Ok, and here is a version with caret insert-like setup:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GUIEdit.au3>
#include <WinAPI.au3>
;

;[0] - Caret Width
;[1] - Caret Height
;[2] - Caret X pos
;[3] - Caret Y pos
;[4] - Caret speed (-1 for static)
;Use this to set blinking solid block caret: [10, 18, 0, 0, 500]
Global $aCaret_Opts[5] = [10, 2, 0, 18, 500]

Global $hBitmap = _WinAPI_CreateSolidBitmap(0, 0xFFFFFF, $aCaret_Opts[0], $aCaret_Opts[1])

Global $iIns_Is_ON = False

$hWnd = GUICreate("Input with caret at desired position", 350, 130)
GUISetFont(14, 400, 1, "DOSLike")

GUICtrlCreateLabel("Number: ", 20, 25, 70, 20)
$Input1 = GUICtrlCreateInput("555-123-456", 100, 20, 200, 25)

$btnOK = GUICtrlCreateButton("&OK", 220, 70, 80, 30, 0)
$btnToggleIns = GUICtrlCreateButton("Toggle INS", 100, 70, 100, 30, 0)

GUISetState()
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE, $btnOK
            Exit
        Case $btnToggleIns
            $iIns_Is_ON = Not $iIns_Is_ON
            GUICtrlSetState($Input1, $GUI_FOCUS)
            _GUICtrlEdit_SetSel($Input1, 0, 0)
    EndSwitch
WEnd

Func WM_COMMAND($hWnd, $msg, $wParam, $lParam)
    Local $nNotifyCode = BitShift($wParam, 16)
    Local $nID = BitAND($wParam, 0xFFFF)
    Local $hCtrl = $lParam
    
    Switch $nID
        Case $Input1
            Switch $nNotifyCode
                Case $EN_CHANGE;, $EN_UPDATE ; Edit (Input) control has been changed
                    If Not $iIns_Is_ON Then Return $GUI_RUNDEFMSG
                    
                    Local $aSelection = _GUICtrlEdit_GetSel($Input1)
                    Local $sInput_Data = GUICtrlRead($Input1)
                    
                    If $aSelection[0] <> $aSelection[1] Then Return $GUI_RUNDEFMSG
                    
                    GUICtrlSetData($Input1, StringLeft($sInput_Data, $aSelection[0]) & StringMid($sInput_Data, $aSelection[0]+2))
                    _GUICtrlEdit_SetSel($Input1, $aSelection[0], $aSelection[0])
                Case $EN_SETFOCUS ; Edit (Input) control has focus
                    If Not $iIns_Is_ON Then Return $GUI_RUNDEFMSG
                    
                    DllCall('user32.dll', 'int', 'CreateCaret', 'hwnd', $lParam, 'ptr', $hBitmap, 'int', 0, 'int', 0)
                    
                    Sleep(10)
                    
                    DllCall("User32.dll", 'int', 'SetCaretPos', 'int', $aCaret_Opts[2], 'int', $aCaret_Opts[3])
                    DllCall('user32.dll', 'int', 'SetCaretBlinkTime', 'uint', $aCaret_Opts[4])
                    DllCall('user32.dll', 'int', 'ShowCaret', 'hwnd', $lParam)
                Case $EN_KILLFOCUS ; Edit (Input) control lost focus
                    If Not $iIns_Is_ON Then Return $GUI_RUNDEFMSG
                    
                    DllCall('user32.dll', 'int', 'HideCaret', 'hwnd', $lParam)
                    DllCall('user32.dll', 'int', 'DestroyCaret')
            EndSwitch
    EndSwitch
    
    Return $GUI_RUNDEFMSG
EndFunc
Edited by MrCreatoR

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Share this post


Link to post
Share on other sites

Fascinating...

These are those small things put together that make AutoIt so powerful.

I also appreciate the caret change when toggling the Insert mode. However, the underscore's caret is an "upperscore"... I have no clue how to put it lower at this time. Perhaps like Yashied demonstrated a while ago, with a (blinking) bitmap? It must be possible anyway, because the SciTE itself does it...

I'm almost ready for the 'DOS alike Input Editor'. It will be a very long code, and rather primitive, that's why I'm asking all those questions...

Share this post


Link to post
Share on other sites

But why underscore? «Blinking solid block caret» imho looks better :).


 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Share this post


Link to post
Share on other sites

But why underscore? «Blinking solid block caret» imho looks better :party:.

I agree 100%! :idea: But it's just for nostalgia reasons... Ah, there we see the good old DOS prompt! :)

Posted Image

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