Source language: Translate to:

Is it possible to force the cursor position in text?

General questions about NeoBook

Moderator: Neosoft Support

Is it possible to force the cursor position in text?

Postby Enigman » Wed Sep 03, 2014 3:44 pm

Is there a way to programmatically set the cursor position with a text box to a specific location? In other words, can I set (force) a cursor offset from the front of the text.

I can currently obtain the cursor position and then use that to split the text into two parts on either side of the cursor, then insert a character, then put the sting back together again. But when I do that, the cursor automatically goes to the end of the string. I want it to stay just behind the inserted character. That would allow my virtual keyboard to continue adding characters right where the cursor is. As it is now, I can only add one character at the cursor, then all other key presses add characters at the end of the string until you click the cursor back to where it was.

Thanks.
User avatar
Enigman
 
Posts: 314
Joined: Tue Apr 12, 2005 3:57 pm
Location: Foothill Ranch, CA

Search cursor position in text

Postby virger » Wed Sep 03, 2014 8:31 pm

Oki, try this example.

From Costa Rica
PURA VIDA
Code: Select all
NBW Publication Source File
(C)2014 NeoSoft Corp.
Title=Playing With TEXT
Language=US
NeoBookVer=5.80
ScreenColors=16777216
ScreenWidth=480
ScreenHeight=300
BkndColor=0
ScreenAutoSize=Yes
LinkColor=16711680
WindowStyle=0
WindowOrder=0
WindowPos=0
WindowProps=31
BiDiMode=0
UseUpdateTimer=Yes
ReturnTime=60
ShapeTransColor=536870912
SplashProps=3
CompiledName=TheText.exe
CompileType=0
MediaType=0
FilesIncluded=1
FontsIncluded=2
FontsToCompile=|
CopyExternalFiles=No
SetupMedia=3
SetupInstDir=C:\MyProgram
SetupTitle=Setup
SetupColors=16711680|0|65535
VersionMajor=1
VersionMinor=0
VersionRelease=0
VersionBuild=0
ReqExLevel=1
CustomFontName=Arial
CustomFontSize=9
CustomFontStyle=0
CustomCharset=1
CacheSize=30
ExtractOp=132
L_OK=OK
L_CANCEL=Cancel
L_YES=Yes
L_NO=No
L_CLOSE=Close
L_ERRORTITLE=Error
L_FINDTITLE=Find
L_FINDPROMPT=Find &What
L_FINDFIRST=&Find First
L_FINDNEXT=Find &Next
L_FINDERROR=Search text not found.
L_PWORDTITLE=Password required
L_PWORDMSG=Before continuing, you must first|enter the correct password.
L_PWORDPROMPT=&Password:
L_PWORDERROR=That's not the right password!
L_MEDIAERROR=In order to play this type of file you must install|the appropriate multimedia hardware and/or|software.
L_INTERNETERROR=Unable to locate Internet Browser software.
L_ABORTFUNCTION=Do you want to cancel this function?
L_EXTRACTERROR=This file could not be extracted and cannot be played.
L_INSTDIRPROMPT=Please enter the drive and directory where you would like this program to be installed. To accept the default drive and directory, simply press Enter.
L_INSTFOLDERPROMPT=Do you wish to create a program folder?
L_INSTRUNPROMPT=Do you want to run
L_INSTDISKPROMPT=Please insert disk #
L_INSTDISKERROR=That's not the correct disk, try again.
L_INSTGENERROR=The installation has terminated.
L_INSTEXITPROMPT=Do you really want to cancel the installation?
L_INSTWINTITLE=Setup
L_INSTPROGTITLE=Extracting Files...
L_SENDEMAIL=Sending Mail...
L_MAILSERVER=Please enter the name of your outgoing email server:
L_COPY=Copy to Clipboard
L_SELECTALL=Select All
L_DONWLOADFILE=Downloading: %s
L_PLEASEWAIT=Please wait...
TrayMenuBegin
MenuName=TrayOpen
MenuText=Open
MenuState=3
MenuKey=0
MenuAction=SetVar "[WindowState]" "Normal"
MenuName=TrayExit
MenuText=Exit
MenuState=3
MenuKey=0
MenuAction=Exit "" ""
MenuEnd
MasterPage
NewPage=New Page
PageStyle=1
PageColor=16777215
PageGradient1=11597992
PageGradient2=9980152
PageGradientDir=0
WallpaperStyle=0
EffectSpeed=0
ObjectType=9
Name=EnText
X=142
Y=0
W=340
H=300
Anchor=0
Text=¶¶Is it possible to force the cursor position in text?¶¶Unread postby Enigman » Wed Sep 03, 2014 5:44 pm¶Is there a way to programmatically set the cursor position with a text box to a specific location? In other words, can I set (force) a cursor offset from the front of the text.¶¶I can currently obtain the cursor position and then use that to split the text into two parts on either side of the cursor, then insert a character, then put the sting back together again. But when I do that, the cursor automatically goes to the end of the string. I want it to stay just behind the inserted character. That would allow my virtual keyboard to continue adding characters right where the cursor is. As it is now, I can only add one character at the cursor, then all other key presses add characters at the end of the string until you click the cursor back to where it was.¶¶Thanks.¶- Enigman -¶http://www.EnigmaCreations.us¶http://www.ResonantEnergies.com
VarName=[Tx]
Align=1
EditMultiLine=Yes
EditLen=0
ObjAction=GetObjectInfo "EnText" "CursorPosition" "[CurPos]"
LineColor=0
LineWidth=1
LineStyle=0
FillColor=15792336
FillPattern=0
Font=Arial
FontSize=12
FontStyle=0
FontCharset=1
TextColor=0
TabOrder=3
ObjectType=15
Name=Tm
X=10
Y=5
W=32
H=32
Anchor=0
Interval=100
ObjAction=GetObjectInfo "EnText" "CursorPosition" "[CurPos]"¶GetObjectInfo "EnText" "SelectedText" "[MkText]"¶if "[MkText]" "<>" ""¶    ShowObject "InfMkText" "None" "0"¶    EnableObject "BtCopy"¶else¶    HideObject "InfMkText" "None" "0"¶    DisableObject "BtCopy"¶endif
ObjectType=8
Name=InfCursor
X=81
Y=2
W=60
H=20
Anchor=0
Font=Arial
FontSize=11
FontStyle=1
FontCharset=1
TextColor=0
Text={\rtf1\ansi\deff0\deftab254{\fonttbl{\f0\fnil\fcharset1 Arial;}}{\colortbl\red0\green0\blue0;\red255\green0\blue0;\red0\green128\blue0;\red0\green0\blue255;\red255\green255\blue0;\red255\green0\blue255;\red128\green0\blue128;\red128\green0\blue0;\red0\green255\blue0;\red0\green255\blue255;\red0\green128\blue128;\red0\green0\blue128;\red255\green255\blue255;\red192\green192\blue192;\red128\green128\blue128;\red0\green0\blue0;\red0\green0\blue0;}\paperw12240\paperh15840\margl1440\margr1440\margt1440\margb1440\margh720\margf720{\*\pnseclvl1\pnucrm\pnstart1\pnhang\pnindent720{\pntxtb}{\pntxta{.}}}¶{\*\pnseclvl2\pnucltr\pnstart1\pnhang\pnindent720{\pntxtb}{\pntxta{.}}}¶{\*\pnseclvl3\pndec\pnstart1\pnhang\pnindent720{\pntxtb}{\pntxta{.}}}¶{\*\pnseclvl4\pnlcltr\pnstart1\pnhang\pnindent720{\pntxtb}{\pntxta{)}}}¶{\*\pnseclvl5\pndec\pnstart1\pnhang\pnindent720{\pntxtb{(}}{\pntxta{)}}}¶{\*\pnseclvl6\pnlcltr\pnstart1\pnhang\pnindent720{\pntxtb{(}}{\pntxta{)}}}¶{\*\pnseclvl7\pnlcrm\pnstart1\pnhang\pnindent720{\pntxtb{(}}{\pntxta{)}}}¶{\*\pnseclvl8\pnlcltr\pnstart1\pnhang\pnindent720{\pntxtb{(}}{\pntxta{)}}}¶{\*\pnseclvl9\pndec\pnstart1\pnhang\pnindent720{\pntxtb{(}}{\pntxta{)}}}¶\endnhere\sectdefaultcl{\pard{\qc\li0\fi0\ri0\sb0\sl\sa0 \plain\f0\fs22\cf0\b [CurPos]}}¶}
HMargin=0
VMargin=0
LineColor=0
LineWidth=1
LineStyle=0
FillColor=14219512
FillPattern=0
TabOrder=5
ObjectType=3
Name=BtPosIni
X=9
Y=56
W=90
H=20
Anchor=0
Text=^Ini:[PosIni]
Align=1
Key=32841
ImageStyle=0
OverlayText=Yes
BevelWidth=0
XPTheme=Yes
ObjAction=setvar "[PosIni]" "[CurPos]"
LineColor=0
LineWidth=1
LineStyle=5
FillColor=14540253
FillPattern=0
Font=Calibri
FontSize=10
FontStyle=3
FontCharset=1
TextColor=0
TabOrder=7
ObjectType=3
Name=BtPosFin
X=9
Y=77
W=90
H=20
Anchor=0
Text=^Fin:[PosFin]
Align=1
Key=32838
ImageStyle=0
OverlayText=Yes
BevelWidth=0
XPTheme=Yes
ObjAction=setvar "[PosFin]" "[CurPos]"
LineColor=0
LineWidth=1
LineStyle=5
FillColor=14540253
FillPattern=0
Font=Calibri
FontSize=10
FontStyle=3
FontCharset=1
TextColor=0
TabOrder=6
ObjectType=8
Name=InfMkText
X=0
Y=215
W=141
H=85
Anchor=0
Font=Arial
FontSize=12
FontStyle=0
FontCharset=1
TextColor=0
Text={\rtf1\ansi\deff0\deftab254{\fonttbl{\f0\fnil\fcharset1 Arial;}}{\colortbl\red0\green0\blue0;\red255\green0\blue0;\red0\green128\blue0;\red0\green0\blue255;\red255\green255\blue0;\red255\green0\blue255;\red128\green0\blue128;\red128\green0\blue0;\red0\green255\blue0;\red0\green255\blue255;\red0\green128\blue128;\red0\green0\blue128;\red255\green255\blue255;\red192\green192\blue192;\red128\green128\blue128;\red0\green0\blue0;\red0\green0\blue0;}\paperw12240\paperh15840\margl1440\margr1440\margt1440\margb1440\margh720\margf720{\*\pnseclvl1\pnucrm\pnstart1\pnhang\pnindent720{\pntxtb}{\pntxta{.}}}¶{\*\pnseclvl2\pnucltr\pnstart1\pnhang\pnindent720{\pntxtb}{\pntxta{.}}}¶{\*\pnseclvl3\pndec\pnstart1\pnhang\pnindent720{\pntxtb}{\pntxta{.}}}¶{\*\pnseclvl4\pnlcltr\pnstart1\pnhang\pnindent720{\pntxtb}{\pntxta{)}}}¶{\*\pnseclvl5\pndec\pnstart1\pnhang\pnindent720{\pntxtb{(}}{\pntxta{)}}}¶{\*\pnseclvl6\pnlcltr\pnstart1\pnhang\pnindent720{\pntxtb{(}}{\pntxta{)}}}¶{\*\pnseclvl7\pnlcrm\pnstart1\pnhang\pnindent720{\pntxtb{(}}{\pntxta{)}}}¶{\*\pnseclvl8\pnlcltr\pnstart1\pnhang\pnindent720{\pntxtb{(}}{\pntxta{)}}}¶{\*\pnseclvl9\pndec\pnstart1\pnhang\pnindent720{\pntxtb{(}}{\pntxta{)}}}¶\endnhere\sectdefaultcl{\pard{\ql\li0\fi0\ri0\sb0\sl\sa0 \plain\f0\fs24\cf0 [MkText]}}¶}
HMargin=4
VMargin=4
LineColor=0
LineWidth=2
LineStyle=6
FillColor=14213368
FillPattern=0
Visible=No
TabOrder=8
ObjectType=3
Name=BtCopy
X=25
Y=167
W=78
H=25
Anchor=0
Text=Ctrl-C
Align=2
Key=16451
ImageStyle=0
BevelWidth=0
XPTheme=Yes
DepressEffect=No
ObjAction=setvar "[ClipBoard]" "[MkText]"
LineColor=0
LineWidth=2
LineStyle=6
FillColor=15987699
FillPattern=0
Font=Arial
FontSize=11
FontStyle=3
FontCharset=1
TextColor=0
Enabled=No
TabOrder=11
ObjectType=9
Name=EntPart2
X=142
Y=150
W=340
H=150
Anchor=0
VarName=[Tx2]
Align=1
EditMultiLine=Yes
EditLen=0
ObjAction=GetObjectInfo "EnText" "CursorPosition" "[CurPos]"
LineColor=0
LineWidth=1
LineStyle=0
FillColor=14737656
FillPattern=0
Font=Arial
FontSize=12
FontStyle=0
FontCharset=1
TextColor=0
Visible=No
TabOrder=2
ObjectType=3
Name=BtSplit
X=25
Y=135
W=78
H=25
Anchor=0
Text=Split
Align=2
Key=16451
ImageStyle=0
BevelWidth=0
XPTheme=Yes
DepressEffect=No
ObjAction=setvar "[TxTmp]" "[Tx]"¶substr "[Tx]" "[CurPos]+1" "999999"   "[Tx2]"¶substr "[Tx]" "1"        "[CurPos]" "[Tx]"¶SizeObject "EnText" "340" "150"¶ShowObject "EntPart2" "None" "0"¶ShowObject "BtJoint" "" ""
LineColor=0
LineWidth=2
LineStyle=6
FillColor=15987699
FillPattern=0
Font=Arial
FontSize=11
FontStyle=3
FontCharset=1
TextColor=0
TabOrder=10
ObjectType=3
Name=BtJoint
X=26
Y=135
W=78
H=25
Anchor=0
Text=Joint
Align=2
Key=16451
ImageStyle=0
BevelWidth=0
XPTheme=Yes
DepressEffect=No
ObjAction=setvar "[Tx]" "[TxTmp]"¶setvar "[Tx1]" ""¶setvar "[Tx2]" ""¶HideObject "EntPart2" "None" "0"¶SizeObject "EnText" "340" "300"¶HideObject "BtJoint" "" ""
LineColor=0
LineWidth=2
LineStyle=6
FillColor=15987699
FillPattern=0
Font=Arial
FontSize=11
FontStyle=3
FontCharset=1
TextColor=0
Visible=No
TabOrder=9


Anything else?
COSTA RICA
PURA VIDA
User avatar
virger
 
Posts: 523
Joined: Mon Sep 18, 2006 12:21 pm
Location: Costa Rica, America Central

Re: Is it possible to force the cursor position in text?

Postby Enigman » Wed Sep 03, 2014 8:57 pm

Thanks, but everything in the sample is stuff I already know how to do. In your sample you see how when you click the cursor into the middle of the text, then you can click the Split button and divides the text in two at the cursor position. Then you click the Join button and it recombines the two halves, BUT notice that the cursor is now at the END of the text. THAT is the problem I am trying to fix. I want the cursor to remain in the middle where I first clicked it and the only way to do that is if I can find something like a command that does:

SetCursor "[text]" "21" -or- SetVar "[CursorPos]" "21"

I need to forceably specify the cursor location somewhere inside the text, not at the end. There are possible alternatives, none of which I know, which is why I am asking the question. :wink:

Thanks again.
User avatar
Enigman
 
Posts: 314
Joined: Tue Apr 12, 2005 3:57 pm
Location: Foothill Ranch, CA

Re: Is it possible to force the cursor position in text?

Postby virger » Thu Sep 04, 2014 10:23 am

Hi there.
Maybe this helps, any ideas to serve, give me more information what you want to do and so I can help better. I am free these days.

Code: Select all
{NeoBook 5 Objects}
NeoBookVer=5.80
ObjectType=9
Name=EntText
X=322
Y=0
W=318
H=480
Anchor=4
VarName=[Tx]
Align=1
EditMultiLine=Yes
EditLen=0
LineColor=0
LineWidth=2
LineStyle=6
FillColor=16314552
FillPattern=0
Font=Arial
FontSize=12
FontStyle=0
FontCharset=1
TextColor=0
TabOrder=2
ObjectType=3
Name=BtSplit
X=170
Y=41
W=78
H=25
Anchor=0
Text=Split
Align=2
Key=16451
ImageStyle=0
BevelWidth=0
XPTheme=Yes
DepressEffect=No
ObjAction=GetObjectInfo "EntText" "CursorPosition" "[CurPos]"¶setvar "[tCurPos]" "[CurPos]"¶setvar "[TxTmp]" "[Tx]"¶substr "[Tx]" "[CurPos]" "999999"   "[Tx2]"¶substr "[Tx]" "1"        "[CurPos]-1" "[Tx]"¶FocusObject "EntPart2"¶SendKeys "" "{CtrlDn}{Home}"
LineColor=0
LineWidth=2
LineStyle=6
FillColor=15987699
FillPattern=0
Font=Arial
FontSize=11
FontStyle=3
FontCharset=1
TextColor=0
TabOrder=3
ObjectType=3
Name=BtJoint
X=38
Y=41
W=78
H=25
Anchor=0
Text=Joint
Align=2
Key=16451
ImageStyle=0
BevelWidth=0
XPTheme=Yes
DepressEffect=No
ObjAction=setvar "[Tx]" "[TxTmp]"¶setvar "[Tx1]" ""¶setvar "[Tx2]" ""¶SetObjectFill "EntText" "Silver" "Solid" "False"¶FocusObject "EntText"¶SendKeys "" "{CtrlDn}{Home}"¶loop "1" "[tCurPos]" "[c]"¶    SendKeys "" "{Right}"¶    .delay "10"¶endloop¶SetObjectFill "EntText" "184,240,248" "Solid" "False"
LineColor=0
LineWidth=2
LineStyle=6
FillColor=15987699
FillPattern=0
Font=Arial
FontSize=11
FontStyle=3
FontCharset=1
TextColor=0
TabOrder=4
ObjectType=9
Name=EntPart2
X=0
Y=239
W=318
H=240
Anchor=0
VarName=[Tx2]
Align=1
EditMultiLine=Yes
EditLen=0
LineColor=0
LineWidth=2
LineStyle=6
FillColor=14739704
FillPattern=0
Font=Arial
FontSize=12
FontStyle=0
FontCharset=1
TextColor=0
TabOrder=6


From COSTA RICA
PURA VIDA
COSTA RICA
PURA VIDA
User avatar
virger
 
Posts: 523
Joined: Mon Sep 18, 2006 12:21 pm
Location: Costa Rica, America Central

Re: Is it possible to force the cursor position in text?

Postby Garic » Thu Sep 04, 2014 11:56 am

On event Text Change write:
SendKeys "" "{Left}"
The cursor will always remain before the printed symbol on the same place.
ks
.............
Image
User avatar
Garic
 
Posts: 107
Joined: Wed Sep 26, 2012 8:42 am

Re: Is it possible to force the cursor position in text?

Postby Enigman » Thu Sep 04, 2014 12:25 pm

On event Text Change write:
SendKeys "" "{Left}"
The cursor will always remain before the printed symbol on the same place.

Thanks, but the Text Change event is only triggered by manually typing in the text box and not by changing the value of the variable. And I don't want the cursor before the added character, I want it after. My Virtual keyboard is only changing the variable values so the text Change event is never triggered.

Thanks.
User avatar
Enigman
 
Posts: 314
Joined: Tue Apr 12, 2005 3:57 pm
Location: Foothill Ranch, CA

Re: Is it possible to force the cursor position in text?

Postby Enigman » Thu Sep 04, 2014 1:53 pm

Virger,

Thanks for the script. I couldn't get it to open as a pub, but reading the script in the code box, I can see what you are doing. Here is my revision of that idea for my current program:

Code: Select all
.
.
.
.......... Reset the cursor position
StrLen "[db.Data.[FocusedObject]]" "[strlen]"
Math "[strlen]-[cursorpos]" "0" "[numloops]"

..... Correct for the backspace key
IfEx "[KeyPress] = Back"
     . If the key press was a backspace, update the loop count
     Math "[numloops]+2" "0" "[numloops]"
EndIf

..... Correct for the return key
IfEx "[KeyPress] = Return"
     . If the key press was a return, update the loop count
     Math "[numloops]-1" "0" "[numloops]"
EndIf

..... Correct for the notes field
IfEx "[FocusedObject] = Notes"
     . In case of trailing returns, help the parse count correctly
     SetVar "[rightstr2]" "[rightstr]~~~"
     . Get the number of returns the cursor will pass through
     StrParse "[rightstr2]" "[#13][#10]" "[unneeded]" "[numlines]"
     Math "[numlines]-1" "0" "[numreturns]"
     IfEx "[numreturns] > 0"
          . If there are returns, update the loop count
          Math "[numloops]-[numreturns]" "0" "[numloops]"
     EndIf
Endif

..... If there are any cursor movements remaining, move the cursor back into the text body
IfEx "[numloops] > 0"
     . Clear the key presses
     SetVar "[allkeys]" ""
     . Accumulate all the key presses
     Loop "1" "[numloops]" "[kiter]"
          SetVar "[allkeys]" "![allkeys]{Left}"
     EndLoop
     . Send all the left keys in one blast
     Suspend "False"
     SendKeys "" "[allkeys]"
     Suspend "True"
EndIf
.
.
.

Using SendKeys is one way to handle it, but it requires a lot of horsing around to make it consistent in both single line text fields and multi-line text fields. It operates vastly different in each due to the possible occurances of return characters in multi-line boxes. When you are pacing through characters moving the cursor, returns count differently than the rest of the characters.

I also modified the way sendKeys was used so it only executed once to move the cursor in one jump instead of having it slowly slide across the box. I also switched from setting the cursor to the front (home) position and moving right, to leaving the cursor at the end where it lands naturally after an edit, and then I count left and slam the cursor in place. This is a better approach since 95% of the time people will be adding more text at the end of the existing text and then no cursor movement is required.

This is all well and good and I have used this approach with other projects. The down side is the script is relatively slow to execute compared to how a physical keyboard operates in a text field. For this project I wanted it to appear that the response times are similar between the virtual keyboard and the physical one. The lag is not as noticeable in a single line field with relatively few characters. But the lag can be huge in a long multi-line notes field where it can take several seconds to react to a key press.

That's why my original question in this thread was aimed at finding a single command way to move the cursor or tell it not to jump to the end after edits.

Thanks for your code suggestions.
User avatar
Enigman
 
Posts: 314
Joined: Tue Apr 12, 2005 3:57 pm
Location: Foothill Ranch, CA

Copy and Paste...

Postby virger » Thu Sep 04, 2014 4:03 pm

Well, here we go. How to copy and apply "code"

1) Go to "code"
2) Select all ("select all")
3) Make copy (Ctrl-C or right click and "copy")
4) Neobook, create an application
5) work area, "paste" (Ctrl-V or go to "edit" and "paste")
6) Ready, so you'll see how the gift works

Until next time
We are PURA VIDA
FROM COSTA RICA
COSTA RICA
PURA VIDA
User avatar
virger
 
Posts: 523
Joined: Mon Sep 18, 2006 12:21 pm
Location: Costa Rica, America Central

Re: Is it possible to force the cursor position in text?

Postby Garic » Thu Sep 04, 2014 8:10 pm

Hi Enigman,

I have just written a plug-in specially for your purpose.
You can move the cursor in object TextEntry to any position.
Tell to me as it works and whether it has helped you with the decision of your problem.

DownloadksEditPlus
ks
.............
Image
User avatar
Garic
 
Posts: 107
Joined: Wed Sep 26, 2012 8:42 am


Return to General NeoBook Discussions

Who is online

Users browsing this forum: Exabot [Bot] and 3 guests