You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: knowledge-base/kb0118.md
+8-35Lines changed: 8 additions & 35 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -225,57 +225,30 @@ on the Keyman system service which emits a fake key event. That way it is possib
225
225
226
226
On Windows, Keyman integrates with applications primarily through the Text Services Framework (TSF). Keyman implements a Text Input Processor (TIP) that communicates with the TSF manager and the target application.
227
227
228
-
When the user types, the TSF manager passes key events and text context to Keyman through the `ITfContext` interface, which provides access to the current edit context within the application. Keyman relies on this interface to retrieve context, determine the current selection, and insert or replace text.
228
+
When the user types, the TSF manager passes key events and text context to Keyman through the `ITfContext` interface, which provides access to the current edit context within the application. Keyman relies on this interface to retrieve context, as a selection object, and insert or replace text.
229
229
For `ITfContext` details see [Learn Microsoft](https://learn.microsoft.com/en-us/windows/win32/api/msctf/nn-msctf-itfcontext).
230
230
231
231
Relevant for Keyman are the following API functions:
232
232
233
-
**`GetStatus()`** — Retrieves the current status of the text context. Keyman uses this to check for the TF_SS_TRANSITORY flag, which indicates temporary or non-standard contexts that may not behave consistently.
233
+
**`GetStatus()`** — Retrieves the current status of the text context. Keyman uses this to check for the `TF_SS_TRANSITORY` flag, which indicates temporary or non-standard contexts that may not behave consistently.
234
234
235
-
**`GetSelection()`** — Retrieves the current text selection or caret position.
235
+
**`GetSelection()`** — Used by Keyman for Windows to get the context next to the cursor.
236
236
237
-
**`SetSelection()`** — Updates the current selection or caret position after Keyman inserts or replaces text.
237
+
**`SetSelection()`** — Updates the current selection or caret position after Keyman inserts or replaces text in the selection retrieved with `GetSelection()`.
238
238
239
-
**`GetText()`** — Retrieves text from a specified range around the caret, giving Keyman the context needed to process complex keyboard rules.
240
239
241
-
**`SetText()`** — Replaces text in a specific range within the context.
240
+
Keyman determines whether an application is compliant by inspecting the status returned by `ITfContext::GetStatus()`. Compliant applications provide a stable, non-transitory context and correctly implement the TSF APIs needed to retrieve context and modify text.
242
241
243
242
Applications can restrict how much surrounding text can be read; Keyman limits its requests to 64 characters of context.
244
243
245
244
<imgsrc="./assets/kb0118/windows-compliant-app-sequence.png"width="75%"alt="compliant sequence on Windows"/>
246
245
247
246
The sequence diagram is for a rule that replaces "D" with "∆".
248
247
249
-
Keyman determines whether an application is compliant by inspecting the status returned by `ITfContext::GetStatus()`.
250
-
251
-
-**Compliant applications** provide a stable, non-transitory context and correctly implement the TSF APIs needed to retrieve context and modify text.
252
-
-**Non-compliant applications** may expose only a transitory context or fail to return reliable selection or text data.
253
-
254
-
If the `TF_SS_TRANSITORY` flag is present or context cannot be read as expected, Keyman treats the application as non-compliant and falls back to legacy behavior, maintaining its own internal context buffer and simulating text operations where possible.
248
+
Note: For both compliant and non-compliant apps. When there is a highlighted section of text if backspace is the determined action from processing the keystroke on Windows Keyman will emit the key (backspace), allowing the application to handle clearing selected text in the correct manner.
255
249
256
250
### Non-compliance on Windows
257
251
258
-
When a non-compliant application is detected, Keyman falls back to **legacy behavior**.
259
-
260
-
With non-compliant applications, Keyman maintains an **internal context buffer** that records the characters it has recently output. This buffered context is used to apply keyboard rules that depend on previously typed characters.
261
-
262
-
263
-
### Limitations of legacy behavior
264
-
265
-
The internal context buffer remains valid only while Keyman has exclusive knowledge of text changes. The buffer becomes invalid if the user performs actions such as:
266
-
267
-
- Moving the caret using the mouse or keyboard
268
-
- Changing the selection
269
-
- Using shortcut keys or menu commands to edit text
270
-
- Switching to another application or document
271
-
272
-
When such an action occurs, Keyman discards its internal context and assumes an empty context. If this happens in the middle of typing a multi-character sequence, the sequence may not be recognized correctly and may need to be retyped.
273
-
274
-
### Simulating text operations
275
-
276
-
Because TSF APIs cannot be relied upon in non-compliant applications, Keyman may simulate text operations by generating keyboard events:
277
-
278
-
-**Backspace key events** are used to delete previously typed characters
279
-
-**Synthetic key events** may be used to insert characters
252
+
If the `TF_SS_TRANSITORY` flag is present or context cannot be read as expected, Keyman treats the application as **non-compliant** and falls back to legacy behavior, maintaining its own internal context buffer and simulating text operations where possible.
280
253
281
-
These simulated events are asynchronous and are processed by the application in sequence. As a result, text deletion and insertion may not always behave exactly as intended, particularly when dealing with composed characters or surrogate pairs.
254
+
The limitations are as stated at the start of this knowledge base article [Working around non-compliant behavior](##-working-around-non-compliant-behavior). Further reading on sending a backspace to an application to perform a delete can be found on the Keyman wiki [here](https://github.com/keymanapp/keyman/wiki/Backspace-and-cluster-deletion).
0 commit comments