Author Topic: react like enter when press space bar with getsting function  (Read 3397 times)

0 Members and 1 Guest are viewing this topic.

Grrr1337

  • Swamp Rat
  • Posts: 812
Re: react like enter when press space bar with getsting function
« Reply #15 on: February 21, 2017, 03:32:04 PM »
Nice code, Gile!
I had something similair but not as good as yours, btw heres another way to write your version:

Code - Auto/Visual Lisp: [Select]
  1. ; (Grread_Getstring_T "Type something: ")
  2. (defun Grread_Getstring_T ( msg / grr Stop str)
  3.   (prompt msg)
  4.   (setq str "")
  5.   (while (not Stop)
  6.     (if (= 2 (car (setq grr (grread))))
  7.       (or
  8.         (eval
  9.           (cdr
  10.             (assoc (cadr grr)
  11.               '(  
  12.                 (13 . (setq Stop T)) ;_ enter
  13.                 (32 . (if (= "" str) (setq Stop T) (setq str (strcat str (princ " ")))))  ;_ space
  14.                 (8 . (and (/= str "") (setq str (substr str 1 (1- (strlen str)))) (princ "\010 \010"))) ;_ backspace
  15.               )
  16.             )
  17.           )
  18.         )
  19.         (setq str (strcat str (princ (chr (cadr grr)))));_ any other char
  20.       )
  21.       (setq Stop T)
  22.     )
  23.   )
  24.   (terpri) (princ)
  25.   str
  26. ); defun Grread_Getstring_T
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)
vevo.bg

ronjonp

  • Needs a day job
  • Posts: 7527
Re: react like enter when press space bar with getsting function
« Reply #16 on: February 21, 2017, 03:48:41 PM »
Nice variation :)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Grrr1337

  • Swamp Rat
  • Posts: 812
Re: react like enter when press space bar with getsting function
« Reply #17 on: February 21, 2017, 03:58:47 PM »
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)
vevo.bg

Lee Mac

  • Seagull
  • Posts: 12912
  • London, England
Re: react like enter when press space bar with getsting function
« Reply #18 on: February 21, 2017, 05:35:38 PM »
Another slight variation:
Code - Auto/Visual Lisp: [Select]
  1. (defun getstringt ( m / g k s )
  2.     (setq s "") (princ m)
  3.     (while
  4.         (and (= 2 (car (setq g (grread nil 2)))) (/= 13 (setq k (cadr g)))
  5.             (cond
  6.                 (   (and (= 32 k) (= s "")) nil)
  7.                 (   (= 08 k)
  8.                     (cond ((= s "")) ((princ "\010 \010") (setq s (substr s 1 (1- (strlen s))))))
  9.                 )
  10.                 (   (setq s (strcat s (princ (chr k)))))
  11.             )
  12.         )
  13.     )
  14.     s
  15. )

(@gile, note that (grread 2) is unnecessarily tracking the cursor.)