Jump to content

Richedit TABkey


Go to solution Solved by SOLVE-SMART,

Recommended Posts

Musashi,

thanks for your answer.

What we need is that if we hit the tabkey the text moves 8 spaces to the right. Nothing special, just like in notepad texteditor.
But from any unknown reason, this does not work in richedit window.

Chees mike

Link to comment
Share on other sites

Hi @mike1950r,

Like @Musashi already suggested, you have to use CTRL+TAB to perform a \t (tab) within a Edit control (like RichEdit).
You can also catch tab-pressing-event by a HotKey and insert your 8 spaces into the RichEdit control, because the default is 4 spaces (1 tab) as far as I know. So if you really need these 8 spaces, adjust your default tab size or use TAB as a HotKey to insert exact 8 spaces.

HotKeySet('{TAB}', '_InsertEightSpaces')

Func _InsertEightSpaces()
    _GUICtrlRichEdit_AppendText($hRichEdit, _StringRepeat(' ', 8))
EndFunc

Best regards
Sven

Edited by SOLVE-SMART

Stay innovative!

Spoiler

🌍 Au3Forums

🎲 AutoIt (en) Cheat Sheet

📊 AutoIt limits/defaults

💎 Code Katas: [...] (comming soon)

🎭 Collection of GitHub users with AutoIt projects

🐞 False-Positives

🔮 Me on GitHub

💬 Opinion about new forum sub category

📑 UDF wiki list

✂ VSCode-AutoItSnippets

📑 WebDriver FAQs

👨‍🏫 WebDriver Tutorial (coming soon)

Link to comment
Share on other sites

A quick google search reveals that TAB does not work in conjunction with RichEdit controls as you would expect from an editor, e.g. see :

richedit-tab-how-to-set-to-8-characters-width

In SciTE you can configure the length (indentation depth) that is triggered by TAB. However, this apparently has no effect on Richedit controls.

 @SOLVE-SMART  's approach works within the RichEdit control, but changes the default behavior of TAB between controls.

Example : Comment the line with HotKeySet in and out to see the difference :

#include <GUIConstantsEx.au3>
#include <GuiRichEdit.au3>
#include <WindowsConstants.au3>
#include <String.au3>

;~ HotKeySet('{TAB}', '_InsertEightSpaces') ; <==== comment in and out

Global $hRichEdit
Example()

Func Example()
        Local $hGui, $iMsg
        Local $idBtnHelp
        Local $idBtnFinish

        $hGui = GUICreate("Example (" & StringTrimRight(@ScriptName, StringLen(".exe")) & ")", 420, 550, -1, -1)
        $hRichEdit = _GUICtrlRichEdit_Create($hGui, "This is a test.", 10, 10, 300, 220, _
                        BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL))

        $idBtnHelp = GUICtrlCreateButton("Help", 10, 400, 150, 35)
        $idBtnFinish = GUICtrlCreateButton("Finish", 200, 400, 150, 35)
        GUISetState(@SW_SHOW)
        While True
                $iMsg = GUIGetMsg()
                Select
                        Case $iMsg = $GUI_EVENT_CLOSE
                                _GUICtrlRichEdit_Destroy($hRichEdit) ; needed unless script crashes
                                Exit
                EndSelect
        WEnd
EndFunc   ;==>Example

Func _InsertEightSpaces()
    _GUICtrlRichEdit_AppendText($hRichEdit, _StringRepeat(' ', 8))
EndFunc

.

Edited by Musashi

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Link to comment
Share on other sites

  • Solution
36 minutes ago, mike1950r said:

I could also hotkey TAB and send CTRL + TAB in the function, right?

Yes you can. For example like this:

HotKeySet('{TAB}', '_SendCtrlTabToRichEdit')

Func _SendCtrlTabToRichEdit()
    _GUICtrlRichEdit_Deselect($hRichEdit) ; This is only to give the RichEdit control the focus.
    Send('^{TAB}')
EndFunc

This is even better than "append 8 spaces" like I suggested before 👍 .

💡 The complete example (previously by @Musashi) with the small adjustments:

Spoiler
#include <GUIConstantsEx.au3>
#include <GuiRichEdit.au3>
#include <WindowsConstants.au3>
#include <String.au3>

HotKeySet('{TAB}', '_SendCtrlTabToRichEdit')

Global $hRichEdit
Example()

Func Example()
        Local $hGui, $iMsg
        Local $idBtnHelp
        Local $idBtnFinish

        $hGui = GUICreate("Example (" & StringTrimRight(@ScriptName, StringLen(".exe")) & ")", 420, 550, -1, -1)
        $hRichEdit = _GUICtrlRichEdit_Create($hGui, "This is a test.", 10, 10, 300, 220, _
                        BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL))

        $idBtnHelp = GUICtrlCreateButton("Help", 10, 400, 150, 35)
        $idBtnFinish = GUICtrlCreateButton("Finish", 200, 400, 150, 35)
        GUISetState(@SW_SHOW)
        While True
                $iMsg = GUIGetMsg()
                Select
                        Case $iMsg = $GUI_EVENT_CLOSE
                                _GUICtrlRichEdit_Destroy($hRichEdit) ; needed unless script crashes
                                Exit
                EndSelect
        WEnd
EndFunc   ;==>Example

Func _SendCtrlTabToRichEdit()
    _GUICtrlRichEdit_Deselect($hRichEdit)
    Send('^{TAB}')
EndFunc

 

But as @Musashi mentioned, if you want to jump between other controls (buttons, etc.) with TAB, you can not.

Best regards
Sven

Edited by SOLVE-SMART

Stay innovative!

Spoiler

🌍 Au3Forums

🎲 AutoIt (en) Cheat Sheet

📊 AutoIt limits/defaults

💎 Code Katas: [...] (comming soon)

🎭 Collection of GitHub users with AutoIt projects

🐞 False-Positives

🔮 Me on GitHub

💬 Opinion about new forum sub category

📑 UDF wiki list

✂ VSCode-AutoItSnippets

📑 WebDriver FAQs

👨‍🏫 WebDriver Tutorial (coming soon)

Link to comment
Share on other sites

think it's working 
by mixing @Musashi hint CRTL+TAB & GUICtrlCreateDummy

#include <GUIConstantsEx.au3>
#include <GuiRichEdit.au3>
#include <WindowsConstants.au3>
#include <String.au3>

__Example()
Func __Example()
        Local $iMsg

        Local $hGui = GUICreate("Example (" & StringTrimRight(@ScriptName, StringLen(".exe")) & ")", 420, 550, -1, -1)
        Local $hRichEdit = _GUICtrlRichEdit_Create($hGui, "This is a test.", 10, 10, 300, 220, _
                        BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL))

        Local $idBtnHelp = GUICtrlCreateButton("Help", 10, 400, 150, 35)
        Local $idBtnFinish = GUICtrlCreateButton("Finish", 200, 400, 150, 35)

        Local $id_Dummy  = GUICtrlCreateDummy()
        Local $aAccelKeys[1][2] = [["{TAB}", $id_Dummy]]
        GUISetAccelerators($aAccelKeys)

        GUISetState(@SW_SHOW)
        While True
                $iMsg = GUIGetMsg()
                Select
                        Case $iMsg = $GUI_EVENT_CLOSE
                                _GUICtrlRichEdit_Destroy($hRichEdit) ; needed unless script crashes
                                GUIDelete($hGui)
                                Exit

                        Case $iMsg = $id_Dummy
                            _InsertEightSpaces()

                EndSelect
        WEnd
EndFunc

Func _InsertEightSpaces()
    Send('^{TAB}')
EndFunc

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...