java_focus_window
Brings an attached Java window to the foreground and confirms whether it actually has keyboard focus before sending shortcuts, so keystrokes do not land in another window.
Instructions
Bring an attached window to the front, and report whether it actually came forward.
Use it before java_send_keys, whose chord goes to whichever window has the keyboard
focus: attaching a window does not give it focus (measured in pyjab#180), so a
shortcut can otherwise land somewhere else entirely.
The reply is the point, not the action. "I asked for focus" and "the window is now
in front" are two different facts, and this tool answers with the second one. It does so
by reading back the state pyjab left behind, because Windows' SetForegroundWindow has
no useful return of its own. So there are three answers, not two:
the window is the foreground window now;
it is not — a normal answer rather than a failure, because Windows refuses foreground activation from a non-interactive session (a service, a scheduled task) and no amount of retrying changes that. An error would be wrong here: nothing failed, and the caller has a fact it can act on;
pyjab answered something that is neither
TruenorFalse, so this server cannot say — reported as such rather than filed under "did not come forward", because "I could not tell" is not a measurement.
It is not free: when the window is not already in front, pyjab sends a space keystroke first, which is what Windows' foreground-activation rules require of a process that wants the foreground — and that keystroke goes to whatever currently has the focus. A caller that cannot tolerate a stray keystroke elsewhere should not call this.
This needs pyjab 1.11.0, which released JABDriver.focus(). The call is probed rather
than assumed, like every pyjab capability here: an install below the pin is told which
release has it instead of raising an AttributeError.
Args: session_id: From java_attach_window.
Returns: Whether the window is now the foreground window, said plainly, with the next step.
Errors:
is_error only for an unknown session, or a pyjab below the pin — which names the
release that has the API. "It did not come forward" is a result, not an error.
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"session_id": "<session_id>"
},
"name": "java_focus_window"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| session_id | Yes |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |