Jump to content

Recommended Posts

Posted (edited)

Hello!

How can I track when working in a while when a user presses a button "+" on the keyboard?

🤔

I will be glad to advice. Thank.

Edited by dilan
Posted

Can you perhaps be a bit more specific?

 

Post a sample code.

Posted
33 minutes ago, dilan said:

Hello!

How can I track when working in a loop when a user presses a button "+" on the keyboard?

🤔

I will be glad to advice. Thank.

 

Not sure how you will implement it, but I think you'll have to use grread

 

(defun rh:get_keypress (keys / key asc c flg)
  (while (null flg)
    (setq key (grread))
    (cond ( (= 13 (cadr key)) (setq flg T))
          ( (= (car key) 2) (setq asc (cadr key) c (chr asc) flg (member asc (vl-string->list keys))))
    )
 )
 c
)

 

pass in keys, which is a string, so if you want to capture the + key (rh:get_keypress "+")

 

they only problem is that it will wait for a key press.

  • Like 1
Posted
10 minutes ago, Jonathan Handojo said:

Can you perhaps be a bit more specific?

 

Post a sample code.

Yes of course

Here is the piece of code:

(while (= 5 (car (setq pnt (grread nil 13 0)))) ; ЦИКЛ ************************
(redraw)
(setq p (cadr pnt))
(setq xof 15
	      yof 10
	      scl (/ (getvar 'viewsize) (cadr (getvar 'screensize)))
		  str (mapcar 'rtos p)
	      txtp (list (+ (car  p) (* xof scl)) (+ (cadr p) (* yof scl)) (+ (caddr p) 1))
		  ); end of setq
(setq txt 
		      "\\PExample!"
			  )
(setq etxt 
            (list 
            (cons 0 "MTEXT")
		    (cons 100 "AcDbEntity")
		    (cons 62 1)
			(cons 100 "AcDbMText")
		    (cons 10 txtp)
		    (cons 40 (* 15 scl))			 
		    (cons 1 txt)
			(cons 7 (getvar 'textstyle))
	        ); end of list
   )	
(if prevtxt (entdel prevtxt))
(setq prevtxt (entmakex etxt))
 ); end of while
(redraw)    
(if prevtxt (entdel prevtxt))

 

Posted
27 minutes ago, dlanorh said:

 

Not sure how you will implement it, but I think you'll have to use grread

 


(defun rh:get_keypress (keys / key asc c flg)
  (while (null flg)
    (setq key (grread))
    (cond ( (= 13 (cadr key)) (setq flg T))
          ( (= (car key) 2) (setq asc (cadr key) c (chr asc) flg (member asc (vl-string->list keys))))
    )
 )
 c
)

 

pass in keys, which is a string, so if you want to capture the + key (rh:get_keypress "+")

 

they only problem is that it will wait for a key press.

Thank!

Posted

And when I click the "+" button in the drawing the text "Example!" is created

Posted
46 minutes ago, dilan said:

And when I click the "+" button in the drawing the text "Example!" is created

 

If you want to include it in your grread code, (setq var (grread...)  returns (x y) to var on an event. If x = 2 it is a keyboard input and y is the ascii value of the key pressed (so for + key this would be (2 43)

  • Like 1
Posted
10 hours ago, dlanorh said:

 

If you want to include it in your grread code, (setq var (grread...)  returns (x y) to var on an event. If x = 2 it is a keyboard input and y is the ascii value of the key pressed (so for + key this would be (2 43)

Thank you so much. Very helpful tip. I will try.

Posted

A quick question are you trying to limit keyboard input to known single keys, INITGET does that or other methods can be used.

Posted
8 hours ago, BIGAL said:

A quick question are you trying to limit keyboard input to known single keys, INITGET does that or other methods can be used.

a solution with a function grread helped me. I solved my problem.

Thank you all for your help.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...