How to Pass key in livecode

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
samjith
Posts: 85
Joined: Tue Mar 31, 2015 10:09 am

How to Pass key in livecode

Post by samjith » Wed Oct 21, 2015 8:35 am

Hi gurus,

How to pass a key from button?.

i have a number of keys to pass inside button. if i click the button. it will pass value (eg:e) into the field where the cursor is.

Please find the attached zip.


Thanks
Samjith
Attachments
help.zip
(768 Bytes) Downloaded 239 times

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4172
Joined: Sun Jan 07, 2007 9:12 pm

Re: How to Pass key in livecode

Post by bn » Wed Oct 21, 2015 10:25 am

Hi Samjith,

I hope I understood what you are trying to do.

put this code into your button

Code: Select all

on mouseUp
   --pass "101"--to show "e" in field "Field"
   put the selectedChunk of field "field" into tChunk -- find out if  field "field" has focus
   if tChunk is "" then -- field has not focus
      answer "field is not selected"
      exit mouseUp
   end if
   
   -- convert number to char
   put  "101" into aKey
   put numToChar(aKey) into tChar
   
   -- find out if the cursor is blinking or a selection has been made in field "field"
   if word 2 of tChunk > word 4 of tChunk then
      put tChar after char (word 4 of tChunk) of  field "field"
   else
      -- handle a selection of one or more chars in field
      put tChar into char (word 2 of tChunk) to (word 4 of tChunk) of field "field"
   end if
end mouseUp
please look up in the dictionary

selectedChunk
numToChar

Kind regards
Bernd

samjith
Posts: 85
Joined: Tue Mar 31, 2015 10:09 am

Re: How to Pass key in livecode

Post by samjith » Wed Oct 21, 2015 1:47 pm

yes, works fine. iam trying this with a large code. thanks

how to pass leftarrow,rightarrow,uparrow,downarrow by button

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4172
Joined: Sun Jan 07, 2007 9:12 pm

Re: How to Pass key in livecode

Post by bn » Wed Oct 21, 2015 2:17 pm

Hi samjith,
how to pass leftarrow,rightarrow,uparrow,downarrow by button
I don't understand, what is leftarrow etc supposed to do.

It is easier to understand when you give a use case. That means what you want to accomplish with arrow keys? Do you want to move the position of the cursor?

Kind regards
Bernd

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10331
Joined: Wed May 06, 2009 2:28 pm

Re: How to Pass key in livecode

Post by dunbarx » Wed Oct 21, 2015 2:46 pm

Bernd.

i think he wants to trap the "arrowKey" message.

@Samjith. Is this true? Please look this up in the dictionary, and experiment for a little while.

Craig Newman

samjith
Posts: 85
Joined: Tue Mar 31, 2015 10:09 am

Re: How to Pass key in livecode

Post by samjith » Thu Oct 22, 2015 5:02 am

Hi,

Actually i want to move the position of the cursor when i click a button

Please find the zip, so you can unuderstand what i meant.

I think the pass command in this stack not working or cursor focus not in the field. very much confused

i need to do deletekey,backspace etc to do like this

Samjith
Attachments
help.zip
(1.47 KiB) Downloaded 215 times

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4172
Joined: Sun Jan 07, 2007 9:12 pm

Re: How to Pass key in livecode

Post by bn » Thu Oct 22, 2015 11:50 am

Hi Samjith,

I still don't understand what you are trying to do but from looking at your stack you try to move the arrowKeys and delete in a field.

The way you did it does not work (or at least I can't get it to work) that you send the arrowKey left message to the field. Apparently the "true" arrowKey left is only received by the field itself when the user types it.

To simulate a arrowkey left and right and backspace and forward delete I made a stack that has 4 buttons that simulate that action by using the selectedChunk.

Is that what you are looking for?

It would help a lot if you could describe what you want to do.

as an example
I want to use a button to move the cursor in a field and another button to delete selections or characters in the field where the cursor is or the whole selection. I am trying to simulate a keyboard with buttons because my users can only click on buttons and can not use a keyboard.
Or something like that as a use case

I know that selectedChunk is complicated but I don't see a way around this for what I guess you are trying to do.

Kind regards
Bend
Attachments
controlField.livecode.zip
use buttons to move cursor right or left and delete text
(1.38 KiB) Downloaded 234 times

samjith
Posts: 85
Joined: Tue Mar 31, 2015 10:09 am

Re: How to Pass key in livecode

Post by samjith » Thu Oct 22, 2015 12:11 pm

Hi Bend,

My wish is to do macro.
store all events in the field (backspace,delete, keys, etc). and wrote it in a button

When i want to load the macro (click button), it will works,



Please find the attached stack. In this stack selectedChunk not work in linux but works in mac.


Thanks
Samjith
Attachments
Sam.zip
(1.05 KiB) Downloaded 242 times

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4172
Joined: Sun Jan 07, 2007 9:12 pm

Re: How to Pass key in livecode

Post by bn » Thu Oct 22, 2015 2:46 pm

Hi Samjith,
In this stack selectedChunk not work in linux but works in mac
I don't have a Linux installation but I know that some operating systems the focus of the field can be taken away by buttons.

To be sure that the button does not take away the focus from the field try in the properties inspector the unselect "traversalOn" or focusable for the button

did the field have focus on Linux? That means the cursor is blinking?
Try it agan on Linux and click into the field before you click the button.
If everything fails try to select the field in the button of you script.

If you want a macro of what was typed into the field I made a stack that records the changes in a "recording" field (the upper one) and that stores it in a custom property of the "recording" field as an array. You can then replay the typing including deletions and including the cursor position by pushing button "replayRecording"

maybe something like this is all you are looking for. If you want to go that way you would have to make yourself familiar with the techniques used here.
Especially arrays and custom properties, as well as script local variables.

Kind regards
Bernd
Attachments
recordTyping.livecode.zip
(2.32 KiB) Downloaded 245 times

samjith
Posts: 85
Joined: Tue Mar 31, 2015 10:09 am

Re: How to Pass key in livecode

Post by samjith » Fri Oct 23, 2015 5:25 am

Hi Bernd,

Thanks for the magical works :D . I wondered, how it works.

I need exactly like the same work. means field 1 is not empty while starts recording,


Thanks

Samjith

Post Reply