Get the screen position of the cursor

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

banjaxd
Posts: 5
Joined: Sat Nov 27, 2021 1:34 pm

Get the screen position of the cursor

Post by banjaxd » Sat Nov 27, 2021 1:46 pm

Hi,

I'm returning to LC after a few years, (the Black Friday all deal was too good to miss) so I do have 'some' experience but I can't figure out how to do this..

I have a requirement to find the screen position of the flashing cursor inside of a multi-line field, so that I can pop open a sub menu at that location. For context, similar to an IDE, I'm hoping the field will recognise a pattern in the string, and pop open a relevant sub menu at location of the cursor.

I'm not sure I've explained that well enough? But I'd be grateful for any advice.

Thanks,
Banjaxd

Klaus
Posts: 13824
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Get the screen position of the cursor

Post by Klaus » Sat Nov 27, 2021 1:50 pm

Hi Banjaxd,

welcome to the forum!
You are probably looking for -> the mouseloc
So you can:

Code: Select all

on mousedown
  popup btn "your popup menu here..." AT THE MOUSELOC
end mousedown
Best

Klaus

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9648
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Get the screen position of the cursor

Post by dunbarx » Sat Nov 27, 2021 4:06 pm

Hi.

But there is a big problem here. In an editable field, such messages as "mouseDown" and "mouseUp" are not sent.

If you hold down the commandKey, at least "mouseUp" is sent. But the current location of the mouseLoc will not be where the blinking cursor is, but rather where the mouse is. This will take just a little fooling around with, but I have to leave now. Klaus, do you se what I mean?

Craig

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9359
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Get the screen position of the cursor

Post by richmond62 » Sat Nov 27, 2021 4:10 pm

The OP is looking for the screen position of the cursor

the mouseLoc will not suffice as a cursor can also be moved via the keyboard.

and NOT for the mouseLoc: these are different things completely.

https://stackoverflow.com/questions/289 ... -the-field

Unfortunately selectionChanged, as in:

Code: Select all

on selectionChanged
   put word 2 of the selectedChunk into fld "fOUTPUT"
end selectionChanged
is not, as far as I can see, going to be much use getting a location where something should appear.
-
SShot 2021-11-27 at 17.37.23.png
Attachments
curses.livecode.zip
Here's the stack
(1.04 KiB) Downloaded 88 times
Last edited by richmond62 on Sat Nov 27, 2021 4:52 pm, edited 1 time in total.

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9359
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Get the screen position of the cursor

Post by richmond62 » Sat Nov 27, 2021 4:45 pm

Naively, perhaps, tried this:

Code: Select all

put the loc of word 2 of the selectedChunk
No joy.

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2718
Joined: Sat Dec 22, 2007 5:35 pm
Location: Genève
Contact:

Re: Get the screen position of the cursor

Post by jmburnod » Sat Nov 27, 2021 5:42 pm

Hi Richmond,

Code: Select all

put the selectedloc
is for you
Kind regards
Jean-Marc
https://alternatic.ch

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9359
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Get the screen position of the cursor

Post by richmond62 » Sat Nov 27, 2021 5:56 pm

Super: just the ticket: Thanks. 8)

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9648
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Get the screen position of the cursor

Post by dunbarx » Sat Nov 27, 2021 7:32 pm

Yes, the selectedLoc. A powerful little gadget.

Here is a stack I made that should get you started. Simply place the cursor in the field and then click on the button.

It is up to you to populate the pullDown menuItems. I assume you will do this by getting the "currentWord of this card" (from the button script).
showPullDown.livecode.zip
(1.16 KiB) Downloaded 80 times
Craig

Klaus
Posts: 13824
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Get the screen position of the cursor

Post by Klaus » Sat Nov 27, 2021 10:40 pm

Hi Craig,
dunbarx wrote:
Sat Nov 27, 2021 4:06 pm
But there is a big problem here. In an editable field, such messages as "mouseDown" and "mouseUp" are not sent.
FALSE and TRUE! :-)
"mouseup" is not sent to an editable field, but "mousedown" is in fact!
Otherwise one could not create an e.g. text formatting popup menu for the user.

Best

Klaus

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9648
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Get the screen position of the cursor

Post by dunbarx » Sun Nov 28, 2021 1:27 am

Klaus.
but "mousedown" is in fact!
No, the "mouseDown" message is not sent in an unlocked field. Never was. Unless you mean to use a right click (button 3?)

Craig

Klaus
Posts: 13824
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Get the screen position of the cursor

Post by Klaus » Sun Nov 28, 2021 2:55 am

Of course I meant:

Code: Select all

on mousedown le_click
  if le_click = 3 then
   ##  right-click, do the popup
  end if
end mousedown
So... :D

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9648
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Get the screen position of the cursor

Post by dunbarx » Sun Nov 28, 2021 3:36 am

OK.

So,banjaxd, how did you intend that the user invoke the popup? Is right-click (or Command-click for button 1 with "mouseUp") acceptable? If so, you do not need the extra button. Its handler can go right into the field script.

And now about that blinking cursor...

Might you lock the field, which would allow the user to click directly on a word and bring the popup directly? To me, this seems like a much better interface. I do not know how the cursor is placed into the text as you originally described it, and you may have good reasons to need it to work that way. But a process that leaves a blinking cursor within a text field does not strike me as a good one as a means to find a target word. When I am looking at a large block of text, sometimes I have to work to find the cursor at all. Better to hilite a word in some way, and then click on it. You could even hilite each word as the cursor moves within the text, and then click on the one of interest.

That sounds like fun.

Craig

banjaxd
Posts: 5
Joined: Sat Nov 27, 2021 1:34 pm

Re: Get the screen position of the cursor

Post by banjaxd » Sun Nov 28, 2021 9:26 am

Thank you to all who have contributed here - some. very interesting points.

@Craig - I feel we're getting close with your example - thank you.

To further explain, this simple application will be used for note taking, so, I will be typing into the field and I intend to use patterns as I type to replace or insert text. An example being "//t" would replace the patten with a date time stamp.
So the text might read " At //t, I met with the stakeholders and discussed..." in this instance, as I type the 't' in '//t' it would be replaced with "2021-11-28 08:18 ". All of this works really well. However, some symbols will have multiple options, where a date time stamp is an absolute, others have options for example, //p might be a 'Person' which should then open a context (sub) menu to select the right person. I've assumed that a good UX would be to open the menu at the cursor location - I could be wrong. But it's important that all of this should happen as I type.

The discussion here suggests using an MS Word, spelling error style, where the UI calls for the user to click on the word with the red underline, this of course get the mouse location. A neat and well known option, but IDE's like visual studio seem to do this really well and I wanted to replicate it to help my note taking.

Am I being unrealistic or are we close? I do really appreciate your feedback.
Thanks again. Banjaxd

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9648
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Get the screen position of the cursor

Post by dunbarx » Sun Nov 28, 2021 4:44 pm

There is no problem at all in making this happen in LiveCode. We just need the rules.

How you decide on the actual user experience is up to you.

Are you saying that, as you type, you will be entering such strings as "//t"? And will do this anticipating that a series of choices will present themselves at that point in the text stream? That is straightforward to put into place, but I could not remember to do that while typing...

Craig

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9359
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Get the screen position of the cursor

Post by richmond62 » Sun Nov 28, 2021 5:18 pm

That is straightforward to put into place, but I could not remember to do that while typing...
Never mind, Richmond reinvented the wheel . . . 8)

Code in text field:

Code: Select all

on keyUp KUP
   put empty into fld "fOUTPUT"
   put the number of chars in fld "fINPUT" into CHARZ
   put char (CHARZ -2) of fld "fINPUT" after fld "fOUTPUT"
   put char (CHARZ -1) of fld "fINPUT" after fld "fOUTPUT"
   put char (CHARZ) of fld "fINPUT" after fld "fOUTPUT"
   put fld "fOUTPUT" into MAGIC
   if MAGIC contains "//t" then
      --- do some magic
   end if
end keyUp KUP
Of course, Richmond's obsession with bunging things in fields (so he can see them) can be circumvented very easily:

Code: Select all

on keyUp KUP
   put empty into MAGIC
   put the number of chars in fld "fINPUT" into CHARZ
   put char (CHARZ -2) of fld "fINPUT" after MAGIC
   put char (CHARZ -1) of fld "fINPUT" after MAGIC
   put char (CHARZ) of fld "fINPUT" after MAGIC
   if MAGIC contains "//t" then
      --- do some magic
   end if
end keyUp KUP

Post Reply

Return to “Talking LiveCode”