jfwscripts/wt-access/WindowsTerminal.JSS

157 lines
4.2 KiB
Text
Raw Permalink Normal View History

2025-03-30 21:24:53 +02:00
; Copyright 2022 Freedom Scientific Inc.
import "uia.jsb"
include "hjconst.jsh"
include "common.jsm"
include "uia.jsh"
globals
int WindowsTerminalObjectID,
object WindowsTerminalTextProvider,
int WindowsTerminalLastKeyPress,
int NoSelect
2025-03-30 21:24:53 +02:00
Script ScriptFileName()
ScriptAndAppNames("Windows Terminal")
EndScript
Void Function FocusChangedEventProcessAncestors(handle FocusWindow, handle PrevWindow)
if GetObjectClassName() == "TermControl"
sayObjectTypeAndText(2)
ELSE
FocusChangedEventProcessAncestors(FocusWindow, PrevWindow)
EndIf
2025-03-30 21:24:53 +02:00
EndFunction
Int Function IgnoreObjectAtLevel(int level)
var
int type = GetObjectSubTypeCode()
if type == WT_LISTBOX ||
type == WT_LISTBOXITEM
return true ; prevent overspeaking with Ctrl+Tab
EndIf
return FALSE
EndFunction
string function GetTextInConsoleWindow()
var
object oNull,
object visibleRanges,
object range
if GetObjectClassName() != "TermControl"
return ""
EndIf
WindowsTerminalTextProvider = FSUIAGetFocusedElement().GetTextPattern()
visibleRanges = WindowsTerminalTextProvider.GetVisibleRanges()
var string textRange = visibleRanges(0)
var string text = textRange.GetText(-1)
return text
2025-03-30 21:24:53 +02:00
EndFunction
script VirtualizeWindow()
var string text = StringTrimTrailingBlanks(GetTextInConsoleWindow())
2025-03-30 21:24:53 +02:00
if !text then
SayMessage(OT_ERROR,cmsgNoTextToVirtualize_L,cmsgNoTextToVirtualize_S)
return
endIf
SayMessage(ot_JAWS_Message,cmsgVirtualizeWindow_L,cmsgVirtualizeWindow_S)
UserBufferClear()
UserBufferAddText(StringTrimTrailingBlanks(text))
2025-03-30 21:24:53 +02:00
UserBufferActivate()
EndScript
; Coming soon: Get the prompt out however still not work
string function GetLastLineFromConsoleText()
var string WindowText = StringTrimTrailingBlanks(GetTextInConsoleWindow())
var stringArray lines = StringSplit (WindowText, "\n", false)
var string LastLine = lines[ArrayLength (lines)-1]
return LastLine
EndFunction
Script TopOfFile()
IF IsJAWSCursor ()
JAWSPageUp ()
EndIf
PerformScript TopOfFile()
EndScript
Script BottomOfFile()
IF IsJAWSCursor ()
RouteJAWSToPc ()
EndIf
PerformScript BottomOfFile()
EndScript
script ToggleSayIndentation()
var int status = GetJCFOption (OPT_INDICATE_INDENTATION)
if status == 0
; turn it on
Say ("Indentation echo on", OT_JAWS_MESSAGE, false)
SetJCFOption (OPT_INDICATE_INDENTATION, 1)
else
; turn it off
Say ("Indentation echo off", OT_JAWS_MESSAGE, false)
SetJCFOption (OPT_INDICATE_INDENTATION, 0)
endif
EndScript
2025-03-30 21:24:53 +02:00
string function ProcessUiaText(string text)
var stringArray lines = StringSplit (text, "\n", false)
var int x = 0
var string out = ""
if ArrayLength(lines) == 1
out = StringConcatenate (out, lines[x])
EndIf
For x = 0 to ArrayLength(lines)
if StringLength (stringStripAllBlanks (lines[x+1])) < 2 & lines[x+1] != "\n" & x != ArrayLength(lines)
out = StringConcatenate (out, StringReplaceChars (lines[x], "\n", " "))
else
out = StringConcatenate (out, lines[x], " ")
2025-03-30 21:24:53 +02:00
EndIf
EndFor
out = StringConcatenate (out, lines[x+1], "\n")
return out
2025-03-30 21:24:53 +02:00
EndFunction
Void Function KeyPressedEvent (int nKey, string strKeyName, int nIsBrailleKey, int nIsScriptKey)
if nKey == 75 | nKey == 77
NoSelect = 1
EndIf
2025-03-30 21:24:53 +02:00
if (nKey > 100000)
WindowsTerminalLastKeyPress = WindowsTerminalLastKeyPress+1
else
WindowsTerminalLastKeyPress = 0
EndIf
EndFunction
void function SelectionChangedEvent( string text, int wasTextSelected, optional int source )
if NoSelect == 1
Say(text,ot_line)
else
SelectionChangedEvent( text, wasTextSelected, source )
EndIf
NoSelect = 0
EndFunction
2025-03-30 21:24:53 +02:00
void function UIANotificationEvent(int notificationKind, int notificationProcessing, string displayString, string activityId, string appname)
;Say (activityId, OT_NONHIGHLIGHTED_SCREEN_TEXT)
2025-03-30 21:24:53 +02:00
var string ki = ProcessUiaText(displayString)
if appname == "WindowsTerminal"
if activityId == "TerminalTextOutput"
2025-03-30 21:24:53 +02:00
if WindowsTerminalLastKeyPress >= 2
WindowsTerminalLastKeyPress = 0
ENDIF
if WindowsTerminalLastKeyPress == 0
Say (ki, OT_NONHIGHLIGHTED_SCREEN_TEXT)
else
WindowsTerminalLastKeyPress = WindowsTerminalLastKeyPress+1
ENDIF
else
Say (ki, OT_NONHIGHLIGHTED_SCREEN_TEXT)
ENDIF
ELSE
UIANotificationEvent(notificationKind, notificationProcessing, displayString, activityId, appname)
EndIf
EndFunction