PyFrame Guide to  wxPython

Copyright and License information  Home

__  A  B  C  D  E  F  G  H  I  L  M  P  R  S  T  U  V  W 

wxStyledTextCtrl - Key Mapping and Execution

Summary:

The first three commands in this set are used to modify keyboard-to-action mappings, the last one is normally used to programmatically invoke functions normally executed by a user pressing a keyboard key. It theoretically can also be used to send any parameterless command to the STC, but this feature is probably of limited use (?).

backgrounder:

The STC has a default mapping between certain keys and functions. This is simplified/summarized below, but also see the source files: contrib/src/stc/Scintilla/src/KeyMap.cxx and contrib/src/stc/Scintilla/include/Scintilla.iface.

The actual keystroke mappings occur in a platform-adaptation layer, e.g., see contrib/src/stc/ScintillaWx.cpp.

The xxEXTEND actions extend the selection, and the WORDPARTxxx actions move between word segments marked by capitalization or underscores; e.g., aMixedCaseIdentifier or a_broken_up_identifier, respectively.

KeyActionDescription
DOWN ARROWLINEDOWNMove caret down one line
SHIFT DOWN ARROWLINEDOWNEXTENDMove caret down one line extending selection to new caret position
CTRL DOWN ARROWLINESCROLLDOWNScroll the document down, keeping the caret visible
UP ARROWLINEUPMove caret up one line
SHIFT UP ARROW LINEUPEXTENDMove caret up one line extending selection to new caret position
CTRL UP ARROW LINESCROLLUPScroll the document up, keeping the caret visible
LEFT ARROWCHARLEFTMove caret left one character
SHIFT LEFT ARROWCHARLEFTEXTENDMove caret left one character extending selection to new caret position
CTRL LEFT ARROWWORDLEFTMove caret left one word
CTRL+SHIFT LEFT ARROWWORDLEFTEXTENDMove caret left one word extending selection to new caret position
ALT LEFT ARROWWORDPARTLEFTMove to the previous change in capitalisation
ALT+SHIFT LEFT ARROWWORDPARTLEFTEXTENDMove to the previous change in capitalisation extending selection to new caret position
RIGHT ARROWCHARRIGHTMove caret right one character
SHIFT RIGHT ARROWCHARRIGHTEXTENDMove caret right one character extending selection to new caret position
CTRL RIGHT ARROWWORDRIGHTMove caret right one word
CTRL+SHIFT RIGHT ARROWWORDRIGHTEXTENDMove caret right one word extending selection to new caret position
ALT RIGHT ARROWWORDPARTRIGHTMove to the next change in capitalisation
ALT+SHIFT RIGHT ARROWWORDPARTRIGHTEXTENDMove to the next change in capitalisation extending selection to new caret position.
HOMEVCHOMEMove caret to before first visible character on line. If already there move to first character on line
SHIFT HOMEVCHOMEEXTENDLike VCHome but extending selection to new caret position
CTRL HOMEDOCUMENTSTARTMove caret to first position in document
CTRL+SHIFT HOMEDOCUMENTSTARTEXTENDMove caret to first position in document extending selection to new caret position
ALT HOMEHOMEDISPLAYMove caret to first position on display line
ALT+SHIFT HOMEHOMEDISPLAYEXTENDMove caret to first position on display line extending selection to new caret position.
ENDLINEENDMove caret to last position on line
SHIFT ENDLINEENDEXTENDMove caret to last position on line extending selection to new caret position
CTRL ENDDOCUMENTENDMove caret to last position in document
CTRL+SHIFT ENDDOCUMENTENDEXTENDMove caret to last position in document extending selection to new caret position
ALT ENDLINEENDDISPLAYMove caret to last position on display line
ALT+SHIFT ENDLINEENDDISPLAYEXTENDMove caret to last position on display line extending selection to new caret position
PRIORPAGEUPMove caret one page up
SHIFT PRIORPAGEUPEXTENDMove caret one page up extending selection to new caret position
NEXTPAGEDOWNMove caret one page down
SHIFT NEXTSCI_PAGEDOWNEXTENDMove caret one page down extending selection to new caret position
DELETECLEARDelete all text in the document
SHIFT DELETECUTCut the selection to the clipboard
CTRL DELETEDELWORDRIGHTDelete the word to the right of the caret
CTRL+SHIFT DELETEDELLINERIGHTDelete forwards from the current position to the end of the line
INSERTEDITTOGGLEOVERTYPESwitch from insert to overtype mode or the reverse
SHIFT INSERTPASTEPaste the contents of the clipboard into the document replacing the selection
CTRL INSERTCOPYCopy the selection to the clipboard
ESCAPECANCELCancel any modes such as call tip or auto-completion list display
BACKDELETEBACKDelete the selection or if no selection, the character before the caret
SHIFT BACKDELETEBACKDelete the selection or if no selection, the character before the caret
CTRL BACKDELWORDLEFTDelete the word to the left of the caret
ALT BACKUNDOUndo one action in the undo history
CTRL+SHIFT BACKDELLINELEFTDelete back from the current position to the start of the line
CTRL 'Z'UNDOUndo one action in the undo history
CTRL 'Y'REDORedoes the next action on the undo history
CTRL 'X'CUTCut the selection to the clipboard
CTRL 'C'COPYCopy the selection to the clipboard
CTRL 'V'PASTEPaste the contents of the clipboard into the document replacing the selection
CTRL 'A'SELECTALLSelect all the text in the document
TABTABIf selection is empty or all on one line replace the selection with a tab character. If more than one line selected, indent the lines.
SHIFT TABBACKTABDedent the selected lines
RETURNNEWLINEInsert a new line, may use a CRLF, CR or LF depending on EOL mode
SHIFT RETURNNEWLINEInsert a new line, may use a CRLF, CR or LF depending on EOL mode
CTRL ADDZOOMINMagnify the displayed text by increasing the sizes by 1 point
CTRL SUBTRACTZOOMOUTMake the displayed text smaller by decreasing the sizes by 1 point
CTRL DIVIDESETZOOMSet the zoom level to 0. This returns the zoom to 'normal,' i.e., no zoom.
CTRL 'L'LINECUTCut the line containing the caret
CTRL+SHIFT 'L'LINEDELETEDelete the line containing the caret
CTRL 'T'LINETRANSPOSESwitch the current line with the previous
CTRL 'U'LOWERCASETransform the selection to lower case
CTRL+SHIFT 'U'UPPERCASETransform the selection to upper case

CmdKeyAssign(key,modifiers,command)

This command is used to add or change an assignment in the key map. Returns None.

The key can be any visible (e.g., 'A') or control character (e.g., Ctrl-A) or a key from the SCK_ enumeration (an internal Scintilla enum). The SCK_ values are directly available in wxPython and are summarized below.

The modifiers are an OR of wxSTC_SCMOD_SHIFT, wxSTC_SCMOD_CTRL, and wxSTC_SCMOD_ALT (or 0 if you don't want to specify a modifier at all).

The message is an action from the second list (messages) below. You can use an action of SCI_NULL (which is not defined in wxPython but has a value of 2172) to set a key mapping to no action, or you can use CmdKeyClear, which will do the same thing. You can execute one of these actions with the CmdKeyExecute method.

Example

CmdKeyAssign('L', wxSTC_SCMOD_SHIFT | wxSTC_SCMOD_CTRL, wxSTC_CMD_LINEDELETE);

Special key value from SCK_ enum

Values to use for message

CommandAction
wxSTC_CMD_BACKTABDedent the selected lines
wxSTC_CMD_CANCELCancel any modes such as call tip or auto-completion list display
wxSTC_CMD_CHARLEFTMove caret left one character
wxSTC_CMD_CHARLEFTEXTENDMove caret left one character extending selection to new caret position
wxSTC_CMD_CHARRIGHTMove caret right one character
wxSTC_CMD_CHARRIGHTEXTENDMove caret right one character extending selection to new caret position
wxSTC_CMD_COPYCopy the selection to the clipboard
wxSTC_CMD_CUTCut the selection to the clipboard
wxSTC_CMD_DELETEBACKDelete the selection or if no selection, the character before the caret
wxSTC_CMD_DELETEBACKNOTLINEDelete the selection or if no selection, the character before the caret. Will not delete the character before at the start of a line.
wxSTC_CMD_DELWORDLEFTDelete the word to the left of the caret
wxSTC_CMD_DELWORDRIGHTDelete the word to the right of the caret
wxSTC_CMD_DOCUMENTENDMove caret to last position in document
wxSTC_CMD_DOCUMENTENDEXTENDMove caret to last position in document extending selection to new caret position
wxSTC_CMD_DOCUMENTSTARTMove caret to first position in document
wxSTC_CMD_DOCUMENTSTARTEXTENDMove caret to first position in document extending selection to new caret position
wxSTC_CMD_EDITTOGGLEOVERTYPESwitch from insert to overtype mode or the reverse
wxSTC_CMD_FORMFEEDInsert a Form Feed character
wxSTC_CMD_HOMEMove caret to first position on line
wxSTC_CMD_HOMEDISPLAYMove caret to first position on display line
wxSTC_CMD_HOMEDISPLAYEXTENDMove caret to first position on display line extending selection to new caret position
wxSTC_CMD_HOMEEXTENDMove caret to first position on line extending selection to new caret position
wxSTC_CMD_LINECUTCut the line containing the caret
wxSTC_CMD_LINEDELETEDelete the line containing the caret
wxSTC_CMD_LINEDOWNMove caret down one line
wxSTC_CMD_LINEDOWNEXTENDMove caret down one line extending selection to new caret position
wxSTC_CMD_LINEENDMove caret to last position on line
wxSTC_CMD_LINEENDDISPLAYMove caret to last position on display line
wxSTC_CMD_LINEENDDISPLAYEXTENDMove caret to last position on display line extending selection to new caret position
wxSTC_CMD_LINEENDEXTENDMove caret to last position on line extending selection to new caret position
wxSTC_CMD_LINESCROLLDOWNScroll the document down, keeping the caret visible
wxSTC_CMD_LINESCROLLUPScroll the document up, keeping the caret visible
wxSTC_CMD_LINETRANSPOSESwitch the current line with the previous
wxSTC_CMD_LINEUPMove caret up one line
wxSTC_CMD_LINEUPEXTENDMove caret up one line extending selection to new caret position
wxSTC_CMD_LOWERCASETransform the selection to lower case
wxSTC_CMD_NEWLINEInsert a new line, may use a CRLF, CR or LF depending on EOL mode
wxSTC_CMD_PAGEDOWNMove caret one page down
wxSTC_CMD_PAGEDOWNEXTENDMove caret one page down extending selection to new caret position
wxSTC_CMD_PAGEUPMove caret one page up
wxSTC_CMD_PAGEUPEXTENDMove caret one page up extending selection to new caret position
wxSTC_CMD_REDORedoes the next action on the undo history
wxSTC_CMD_SELECTALLSelect all the text in the document
wxSTC_CMD_TABIf selection is empty or all on one line replace the selection with a tab character. If more than one line selected, indent the lines
wxSTC_CMD_UNDORedoes the next action on the undo history
wxSTC_CMD_UPPERCASETransform the selection to upper case
wxSTC_CMD_VCHOMEMove caret to before first visible character on line. If already there move to first character on line
wxSTC_CMD_VCHOMEEXTENDLike VCHome but extending selection to new caret position
wxSTC_CMD_WORDLEFTMove caret left one word
wxSTC_CMD_WORDLEFTEXTENDMove caret left one word extending selection to new caret position
wxSTC_CMD_WORDRIGHTMove caret right one word
wxSTC_CMD_WORDRIGHTEXTENDMove caret right one word extending selection to new caret position
wxSTC_CMD_ZOOMINMagnify the displayed text by increasing the sizes by 1 point
wxSTC_CMD_ZOOMOUT Make the displayed text smaller by decreasing the sizes by 1 point
A few values are not defined in wxPython as of this writing, but should be as they are even in the default keymapping shown earlier on this page. They were added in CVS as this was being written.
wxSTC_CMD_DELLINELEFT: Use 2395Delete back from the current position to the start of the line
wxSTC_CMD_DELLINERIGHT: Use 2396Delete forwards from the current position to the end of the line
wxSTC_CMD_WORDPARTLEFT: Use 2390Move to the next change in capitalisation
wxSTC_CMD_WORDPARTLEFTEXTEND: Use 2391Move to the previous change in capitalisation extending selection to new caret position
wxSTC_CMD_WORDPARTRIGHT: Use 2392Move caret right one word extending selection to new caret position
wxSTC_CMD_WORDPARTRIGHTEXTEND: Use 2393Move to the next change in capitalisation extending selection to new caret position.
top

CmdKeyClear(key,modifiers)

Sets the keyboard action for the keyboard key specified by the method arguments to SCI_NULL, which effectively causes no action for that key. The arguments key and modifiers are identical to those that would be used in the CmdKeyAssign method, above. Returns None.

top

CmdKeyClearAll()

Actually completely removes all entries from the key-map. Doesn't restore the defaults: there's no method to do so, although obviously one could do that manually. Returns None.

top

CmdKeyExecute(cmd)

This method is used to programmatically execute one of the key-actions (wxSTC_CMD_xxx) that is normally executed by a keypress. For the cmd argument, use one of the values in the message table shown for the CmdKeyAssign method. Returns None.

Note that several of the messages have direct wxPython methods that you can use instead; for example,

HomeDisplay()
rather than CmdKeyExecute(wxSTC_CMD_HOMEDISPLAY). See this page for those methods.

top