Page 1 of 1
changing inkey to lower case
Posted: Sat Oct 22, 2011 11:07 pm
by townsend
As the user enters text, I'm using this routine, to change each character to lower case, on the fly.
Code: Select all
on keyup
put lower(me) into me
select after text of me
end keyup
It works okay, until the user, uses the arrow keys to move the cursor back for an edit.
That Select command there, is nice, that you can place the cursor before or after or anywhere in the text.
But how to I query the text field to find out what position in the text, the cursor is currently at?
Re: changing inkey to lower case
Posted: Sat Oct 22, 2011 11:42 pm
by bn
Hi townsend,
have a look at rawKeyUp, it catches the arrowKey and all the others, and at selectionchanged / selectedChunk. If the insertion point is just the cursor without a selection then word 4 of the selectedChunk is 1 lower than word 2 of the selectedChunk. E.g char 20 to 19 of field 1. KeyUp does not catch the arrowKey. The selectionChanged handler is for handling the shift key and the arrowKey to make an actual selection or the user click-drags to make a selection.
put this into a test field and have a second field for the output:
Code: Select all
on rawKeyUp theKey
put the selectedchunk into tChunk
if word 4 of tChunk < word 2 of tChunk then \
put "the chunk: " & tChunk & cr & "the key:" && theKey & cr & "no of characters in field: " & length(me) into field 2
pass rawKeyUp
end rawKeyUp
on selectionChanged
put the selectedChunk into field 2
end selectionChanged
Kind regards
Bernd
Re: changing inkey to lower case
Posted: Wed Oct 26, 2011 8:58 pm
by townsend
Thanks for the code Bernd-- This is a good example of-- 'the selectedchunk' function.
Code: Select all
on rawKeyUp theKey
put the selectedchunk into tChunk
put "keyword 'the selectedchunk' =" & cr & tChunk & cr & cr into fld "status"
put "the key code is:" && theKey & cr after fld "status"
put "# of characters in field: " & length(me) after fld "status"
pass rawKeyUp
end rawKeyUp
Now I see how this works.

- 137 rawkey.jpg (30.35 KiB) Viewed 5049 times
Let me ask you this. When I'm using: 'on keyDown' or the 'on rawKeyDown' the inkey value has yet to be displayed. But when I change the value of the passed inkey, it does not change the value of the original key press. The original key press always shows up in the field. Is there any way, not only to capture the inkey, but change it before it appears in the field?
Re: changing inkey to lower case
Posted: Wed Oct 26, 2011 9:10 pm
by mwieder
There is, but you have to do it very explicitly yourself. Two things to do: first, set the character into the field, and (very importantly) *don't* pass the message at the end. Something like this:
Code: Select all
on keyUp pKey
if pKey is space then
-- for the simple case where it's just after the existing text
put "*" after me
end if
-- don't pass keyUp
-- pass keyUp
end keyUp
Re: changing inkey to lower case
Posted: Thu Oct 27, 2011 6:43 pm
by townsend
Okay-- thanks.
Here's the final code on converting to lowercase on the fly.
Code: Select all
on keydown inkey
put the selectedchunk into tChunk
put word 4 of tchunk into pos
if chartonum(inkey) >= 65 and chartonum(inkey) <=90 then
put lower(inkey) after char pos of me
else
pass keydown
end if
end keydown
Re: changing inkey to lower case
Posted: Fri Oct 28, 2011 12:51 am
by Mark
Hi,
I think you should be able to do this directly:
Code: Select all
set the caseSensitive to true
if inkey >= "A" and inkey <="Z" then
-- etc
Kind regards,
Mark
Re: changing inkey to lower case
Posted: Fri Nov 18, 2011 8:26 pm
by townsend
There's still one thing I'm having a problem with. I has to do with the instance where a user highlights a couple of letters in the middle of a word, and wants to replace them with another couple of letters.
Code: Select all
if length(the selectedtext of me) >0 then
replace (the selectedtext of me) with lower(inkey) of me
end if
This code replaces the first letter okay, but because the cursor ends up being positioned at the beginning of the field, the second letter ends up in the wrong place. I know the position, where the cursor should be, but don't know how to position it there.
Is there a way to move a cursor within a field, with code?
Re: changing inkey to lower case
Posted: Fri Nov 18, 2011 8:33 pm
by Mark
Hi,
You can set the cursor in a field with
Best,
Mark