yajva General User

Joined: 30 Jan 2009 Posts: 8
|
Posted: Fri Jan 30, 2009 4:31 am Post subject: How to include backspace in "textcursor.setstring" |
|
|
Hello,
I have a key handler in a macro which contextually determines the text from the key pressed. ( I am actually writing a macro to type Sanskrit in OO phonetically, slightly different in behavior from the keyboard layouts already available.) This sometimes requires that i backspace an already displayed character. Including ASCII code for backspace in the string argument to setstring literally outputs a code on to the document. (However I can achieve the desired result by searching for backspace in the string and moving the cursor back). This seems a little unintuitive to me. This does not seem to be the behaviour on microsoft office word. Is there an easy way around this ?
I have provided the working code below.
Function KeyHandler_keyPressed(oKeyEvent as new com.sun.star.awt.KeyHandler) As Boolean
Dim myDoc as Object
Dim controller as Object
Dim viewCursor as Object
Dim myText as Object
Dim textCursor as Object
Dim aString as String
Dim rString as string
dim ctxtChr
dim i, j
dim c
dim texta, tmp
myDoc = ThisComponent
controller = myDoc.getCurrentController()
viewCursor = controller.getViewCursor()
myText = viewCursor.getText()
textCursor = myText.createTextCursorByRange(viewCursor)
textCursor.goLeft(1, true)
aString = textCursor.getString()
if (aString = "") then
ctxtChr = uc_Ig
else
ctxtChr = asc(aString)
end if
KeyHandler_keyPressed = processKey(oKeyEvent.keyChar, ctxtChr, rString)
if not (rString = "") then
textcursor.gotoEnd(false)
for i = 1 to len(rString)
j = mid(rString,i,1)
if (asc(j) = then
textCursor.goLeft(1, true)
textCursor.setString("")
else
textCursor.setString(j)
textcursor.gotoEnd(false)
end if
etc etc
Thanks and Regards
Yajvan |
|