Rebol Talk Forum  |  REBOL Discussions  |  REBOL View  |  Topic: Keyboard editing function.....
Pages: [1] Print
Author Topic: Keyboard editing function.....  (Read 509 times)
jfdutcher
Jr. Member
**
Offline Offline

Posts: 95


View Profile
Keyboard editing function.....
« on: June 09, 2004, 04:14:46 PM »

The brief code below is inserted with "insert-event-func".

If I comment out the two tests for 'lerft' and 'right', the
test for numerics works fine, and limits input accordingly.

If I uncomment the 'left'/'right' tests...those two tests work fine....but their presence does, for some reason,
then nullify the following numerics test....and the script
commences to tolerate alphas or whatever. I'm puzzled because it seems as though the numeric key entries should pass through the two arrow key tests and simply respond as before (when those two were 'commented' ?
***********
Code snippet:
key-event: func [face event] [
    if event/type = 'key [  
          ch: event/key
     if find "left" ch [return event]
     if find "right" ch [return event]
     if not find "0123456789" ch [alert "Only digits can be entered" return none]
    ]
    if event/type = 'close [
                    print "Removing event function"
                    remove-event-func :key-event
    ]
    RETURN event
]  
Logged
CarlRead
Full Member
***
Offline Offline

Posts: 105


View Profile
Keyboard editing function.....
« Reply #1 on: June 10, 2004, 03:17:44 AM »

I'm not sure quite how you code works,  (working, or supposted-to-be working examples are the easiest to de-bug), but it may be you need a copy where the key-event is captured.  ie...

ch: copy event/key

Ask again if that doesn't fix it.
« Last Edit: June 10, 2004, 03:18:42 AM by CarlRead » Logged

- Carl Read
jfdutcher
Jr. Member
**
Offline Offline

Posts: 95


View Profile
Keyboard editing function.....
« Reply #2 on: June 10, 2004, 06:34:23 AM »

This is the result of adding the 'copy':
Script: "www.lotterychecker.com" (none)
** Script Error: copy expected value argument of type: series port bitset
** Where: evt-func
** Near: ch: copy event/key
if find
********************
I'll add the 'whole' script since it is not
too large...if you run this and then alternatively comment out the two lines checking for 'left' and 'right' keys..while
trying to filter for only numeric key entries...you will see ,
I believe, how the presence or absence of those two
tests adversly effects whether the test for digits only which follows actually works or not.
Here's the script:

Rebol[Title: "www.lotterychecker.com"]
key-event: func [face event] [
    if event/type = 'key [  
          ch: copy event/key
     if find "left" ch [return event]
     if find "right" ch [return event]
     if not find "0123456789" ch [alert "Only digits can be entered" return none]
    ]
    if event/type = 'close [
                    print "Removing event function"
                    remove-event-func :key-event
    ]
    RETURN event
]
insert-event-func :key-event    

lotto-layout: layout [backdrop green across tab tab
   title red "WWW.LOTTERYCHECKER.COM"
   below
   style numbox field 30x30 font [size:35]
   h1 {A tool with which you store, manage and check groups of               

   lottery ticket numbers:} across
   h1 blue "Select the game you wish to work with here --->"
   game: choice 200x45 "PowerBall" "New York Lotto" "Thunderball" "MegaMillions"
     return below
   h2 {Indicate the function you wish to perform by clicking one                

   radio button below:}
   across tab
   radbutchk: radio h2 blue {Check the winning number below against all my tickets:}
   return tab
   radbutadd: radio h2 blue "Add number below to my file for this game"
   return tab
   radbutdel: radio h2 blue "Delete number below from my file for this game"    
   return tab
   radbutver: radio h2 blue "Verify number below is on file for this game"
   return tab
   radbutlst: radio h2 blue {List all numbers for this game (no number need be entered

below):}
   return
   below
   h2 {Enter (6) two digit numbers below to reflect the requirements of             

   the game you selected above. Use the last box for entering winning bonus
   numbers for N.Y. Lotto, UK Nat'l. Lottery:}
   across
   num1: numbox "00" tab
   num2: numbox "00" tab
   num3: numbox "00" tab
   num4: numbox "00" tab
   num5: numbox "00" tab
   num6: numbox "00" tab
   num7: numbox "00"
   return
   box red 700x3 return
   tab tab button 96x45 font [size: 25] "GO !!"  
   tab button 96x45 font [size: 25]"Reset" [clear-fields lotto-layout show lotto-layout]
]
focus num1
view lotto-layout
 
Logged
Gabriele
Full Member
***
Offline Offline

Posts: 182


View Profile WWW
Keyboard editing function.....
« Reply #3 on: June 10, 2004, 10:11:39 AM »

Quote
if find "left" ch [return event]
   if find "right" ch [return event]
 
Maybe you didn't realize this:

Code:
>> find "right" #"r"
== "right"
>> find "right" #"i"
== "ight"
>> find "right" #"g"
== "ght"
>> find "right" #"h"
== "ht"
>> find "right" #"t"
== "t"

I think that what you want is actually:

Code:
if ch = 'left [return event]
« Last Edit: June 10, 2004, 10:12:09 AM by Gabriele » Logged
jfdutcher
Jr. Member
**
Offline Offline

Posts: 95


View Profile
Keyboard editing function.....
« Reply #4 on: June 10, 2004, 12:14:36 PM »

Thanks a lot,

You have it just right...that IS what I want !!

John D.
Logged
CarlRead
Full Member
***
Offline Offline

Posts: 105


View Profile
Keyboard editing function.....
« Reply #5 on: June 10, 2004, 04:13:06 PM »

Seems you have your answer, so that's good.

I'd just like to point out you can indent code here by clicking on the "CODE" button you'll see on the posting page.  And by clicking on it again at the end of your code and it'll put a close tag in as well so you can add comments afterwards.
Logged

- Carl Read
Pages: [1] Print 
Rebol Talk Forum  |  REBOL Discussions  |  REBOL View  |  Topic: Keyboard editing function.....
Jump to:  

  
Quick Search...

Advanced search
  
Welcome, Guest. Please login or register.
Did you miss your activation email?
August 21, 2008, 03:44:28 PM
Username: Password: Session Length:
  

News: 01-09-08

Alpha version of REBOL 3 has been released!


  
2225 Posts in 578 Topics by 1651 Members
Latest Member: Prebrotte

  Rebol Talk Forum | Powered by SMF 1.0.9.
© 2001-2005, Lewis Media. All Rights Reserved.

RT design by Defiant Pc