Get the screen position of the cursor
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Get the screen position of the cursor
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
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
Re: Get the screen position of the cursor
Hi Banjaxd,
welcome to the forum!
You are probably looking for -> the mouseloc
So you can:
Best
Klaus
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
Klaus
-
- VIP Livecode Opensource Backer
- Posts: 9676
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Get the screen position of the cursor
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
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
-
- Livecode Opensource Backer
- Posts: 9397
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: Get the screen position of the cursor
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:
is not, as far as I can see, going to be much use getting a location where something should appear.
-
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
-
- Attachments
-
- curses.livecode.zip
- Here's the stack
- (1.04 KiB) Downloaded 91 times
Last edited by richmond62 on Sat Nov 27, 2021 4:52 pm, edited 1 time in total.
-
- Livecode Opensource Backer
- Posts: 9397
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: Get the screen position of the cursor
Naively, perhaps, tried this:
No joy.
Code: Select all
put the loc of word 2 of the selectedChunk
-
- 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
https://alternatic.ch
-
- Livecode Opensource Backer
- Posts: 9397
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: Get the screen position of the cursor
Super: just the ticket: Thanks.
-
- VIP Livecode Opensource Backer
- Posts: 9676
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Get the screen position of the cursor
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).
Craig
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).
Craig
Re: Get the screen position of the cursor
Hi Craig,
"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
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
-
- VIP Livecode Opensource Backer
- Posts: 9676
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Get the screen position of the cursor
Klaus.
Craig
No, the "mouseDown" message is not sent in an unlocked field. Never was. Unless you mean to use a right click (button 3?)but "mousedown" is in fact!
Craig
Re: Get the screen position of the cursor
Of course I meant:
So...
Code: Select all
on mousedown le_click
if le_click = 3 then
## right-click, do the popup
end if
end mousedown
-
- VIP Livecode Opensource Backer
- Posts: 9676
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Get the screen position of the cursor
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
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
Re: Get the screen position of the cursor
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
@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
-
- VIP Livecode Opensource Backer
- Posts: 9676
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Get the screen position of the cursor
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
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
-
- Livecode Opensource Backer
- Posts: 9397
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: Get the screen position of the cursor
Never mind, Richmond reinvented the wheel . . .That is straightforward to put into place, but I could not remember to do that while typing...
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
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