sending a Backspace to a on Keyup commnd

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

chipsm
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 244
Joined: Wed May 11, 2011 7:50 pm
Location: Southern California

Re: sending a Backspace to a on Keyup commnd

Post by chipsm » Tue Oct 01, 2019 4:27 am

Hi Folks,
I do appreciate all of your responses to my question about sending the "BackSpaceKey"
Again, the suggestion that Richmond2 gave was the one that worked well for me,
I am sure that some of you might be curious about my need for such a bit of code.

If you are interested in seeing my sample of why I wanted this, I will post my sample LC application.
I await your response.
Clarence Martin
chipsm@themartinz.com

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm
Location: Göttingen, DE

Re: sending a Backspace to a on Keyup commnd

Post by [-hh] » Tue Oct 01, 2019 8:14 am

Just to make things as simple as possible:

Code: Select all

on mouseUp
  select char 5 of fld 1 -- or whatever char
  type numToChar(8)
end mouseUp
Works with LC 6/7/8/9.

Type sends rawkeydown and rawkeyup, so cannot be trapped by keydown/keyup.
shiftLock happens

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: sending a Backspace to a on Keyup commnd

Post by bogs » Tue Oct 01, 2019 10:12 am

That is pretty simple and slick, nice one -hh.
Image

chipsm
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 244
Joined: Wed May 11, 2011 7:50 pm
Location: Southern California

Re: sending a Backspace to a on Keyup commnd

Post by chipsm » Tue Oct 01, 2019 11:56 am

HH,
your script works also!
Clarence Martin
chipsm@themartinz.com

chipsm
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 244
Joined: Wed May 11, 2011 7:50 pm
Location: Southern California

Re: sending a Backspace to a on Keyup commnd

Post by chipsm » Tue Oct 01, 2019 12:03 pm

For anyone interested - here is my sample application.
It includes a US States file to load into the list.
Do with it whatever you want.
It is a drop list that is parsed by typing letters in the parsing field or clicking the down arrow to get a full list.
Attachments
stateDropDownList.zip
(3.17 KiB) Downloaded 217 times
Clarence Martin
chipsm@themartinz.com

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm
Location: Göttingen, DE

Re: sending a Backspace to a on Keyup commnd

Post by [-hh] » Tue Oct 01, 2019 4:15 pm

Clarence,

this is a nice idea.

Recently I made a search field that uses a different approach ('textchanged') and has several styling features (highlights the found string).

It also searches for lines which contain the search string, like Hypercard's "find string".
So you can for example find "Kentucky" uniquely by typing one of ck,ke,ky,tu.

It is all self contained.
All you need is a search field, set text properties and the width of it.
Thereafter (not before) set the script of the search field as follows and click or type in it.

Just for fun (and giving more ideas).

Code: Select all

local sL0, ff="output"

on textchanged
  lock screen; lock messages
  put me into t
  put length(t) into l
  -- LC 6 has no "filter into", so:
  put sL0 into sL
  filter sL with ("*"&t&"*")
  put the num of lines of sL into sN
  if sN > 0 then
    put sL into fld ff 
    if l>0 then
      repeat with i=1 to sN
        put offset(t,line i of sL)-1 into o1
        set backcolor of char o1+1 to o1+l of line i \
              of fld ff to "yellow"
      end repeat
    end if
  else
    put "Found nothing" into fld ff
    set foreColor of char 1 to -1 of fld ff to "blue"
  end if
  setSize
end textchanged

on setSize
  lock screen; lock messages
  put the width of me into w
  put the height of this card into h0
  put h0 - the effective textheight of fld ff into h1
  put h1 - the top of fld ff into h
  put the formattedHeight of fld ff into fh
  set vscrollbar of fld ff to (fh > h)
  set height of fld ff to min(h,fh)
  set width of fld ff to max(w,the formattedWidth of fld ff)
  set topleft of fld ff to the botleft of me
end setSize

on openField -- get the statesList
  set itemdel to "#"
  put line 2 to -2 of (item 3 of the script of me) into sL0 
  if there is no fld ff then
    lock screen; lock messages
    clone me; put it into f
    set name of f to ff
    set listbehavior of f to true
    set fixedLineHeight of f to true
    set borderColor of f to "235,235,235" -- mercury
    set hgrid of f to true
    set topleft of f to the botleft of me
  end if
  textchanged
end openField

#--states list start
Alabama
Alaska
Arizona
Arkansas
California
Colorado
Connecticut
Delaware
Florida
Georgia
Hawaii
Idaho
Illinois
Indiana
Iowa
Kansas
Kentucky
Louisiana
Maine
Maryland
Massachusetts
Michigan
Minnesota
Mississippi
Missouri
Montana
Nebraska
Nevada
New Hampshire
New Jersey
New Mexico
New York
North Carolina
North Dakota
Ohio
Oklahoma
Oregon
Pennsylvania
Rhode Island
South Carolina
South Dakota
Tennessee
Texas
Utah
Vermont
Virginia
Washington
West Virginia
Wisconsin
Wyoming
#--states list end
shiftLock happens

chipsm
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 244
Joined: Wed May 11, 2011 7:50 pm
Location: Southern California

Re: sending a Backspace to a on Keyup commnd

Post by chipsm » Tue Oct 01, 2019 4:35 pm

The main thing that I like about LiveCode is its versatility.
L C offers so many ways to achieve a result, you just need imagination and problems will be solved.
Cool Stuff.
Clarence Martin
chipsm@themartinz.com

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

Re: sending a Backspace to a on Keyup commnd

Post by richmond62 » Tue Oct 01, 2019 4:52 pm

Type sends rawkeydown and rawkeyup, so cannot be trapped by keydown/keyup.
That's why, in my code above, I had to have 2 type signals so the first one would
wipe out the backslash character. 8)

Lagi Pittas
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 365
Joined: Mon Jun 10, 2013 1:32 pm

Re: sending a Backspace to a on Keyup commnd

Post by Lagi Pittas » Sun Jan 10, 2021 3:20 am

Hi All,

I decided to refactor some old code that has been working for a few years and used the select and insert method on the focused object.

I thought rawkeyup or keyup would make it easier so started with that and kept getting a cant find handler error.

I did a search and found this thread using ALMOST the same method except the whole send was inside a single string except mine was
originally

Code: Select all

Send "Keyup" && lcKey


I copied Craig's method exactly as well and gave it its own key but still no joy.

I tested different ways including going back to version 6 - Now after 3+ hours over 2 days I give up I give Up.
I must be missing something simple - can't see the forest for the trees.

The real code is a virtual keyboard that works perfectly except occasionally when delete and a cursor is used (no big problem) but it is something that always bugged me.

Can someone please take a look at the attached (version 6 LC) stack and see where I am going wrong

Thanks so much

*** EDIT
I came back into it today and the 4 buttons with a behavior weren't firing.
Turns out just before I uploaded I decided to rename the stack from untitled to upkey - LC did not update the behavior name
so i have reuploaded - still doesn't work

Lagi
Attachments
KeyUp2.zip
(1.03 KiB) Downloaded 165 times

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

Re: sending a Backspace to a on Keyup commnd

Post by dunbarx » Mon Jan 11, 2021 12:46 am

Lagi.

Two things. One, you need something like this, not what you had:

Code: Select all

on mouseUp
   send "keyup" && random(9) to me
end mouseUp

on keyUp tkey
   put tKey into fld "f1"
end keyUp
That was the easy part. I reWrote your button script, and it did not work. I made a new field, changed the destination, and it did. Not sure what is "special" about your field "F1". Maybe fool around and find out, or delete it and make a new one.

Craig

Lagi Pittas
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 365
Joined: Mon Jun 10, 2013 1:32 pm

Re: sending a Backspace to a on Keyup commnd

Post by Lagi Pittas » Mon Jan 11, 2021 12:58 am

Hi Thanks Craig,
I was playing around so much I changed your code to "hard" code put it inside the quotes as you did then put it outside
I was going loopy i will delete all the buttons and make 1 only without a behavior and carry on from there.

In fact looking at that it wont do what i want it to do. I was going to het this working and then use rawkeyup.

The ide is that i will let LC control the backspace delete and insertion by simulating the keypress in the field.
The way I have got it working at the moment I append after and trap the arrow and delete keys and insert - but I think its messy especially when they delete backwards at the beginning of a line. This is why i decided to see if i can inset using the inbuild keyup/rawkeyup handlers of the field.

Thanks for your help

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”