Author Topic: Get the key value of the keyboard and mouse with gread  (Read 3008 times)

0 Members and 1 Guest are viewing this topic.

xiaxiang

  • Guest
Get the key value of the keyboard and mouse with gread
« on: April 18, 2011, 09:29:52 PM »
I have a code like that:
Code: [Select]
(setq roop t)
(while roop
    (princ "\n Shift+RightMouse=... / RightMouse=... / LeftMouse=... /Space;Enter=Quit:")
    (setq gr (grread nil 4 2)
  ga (car gr)
  gb (cadr gr))
      (cond
      ((= ga 3);;;LeftMouse
       ... 
       ...
      )
      ((member gr '((2 13)(2 32))) ;; "" Space or Enter
(setq roop nil))
      ((=  ga 11) ;;;RightMouse
       .....           
       .....
      )
      ((member gr '((11 1000))) ;;;Shift+RightMouse
       ....
       ....
   )
  )
  )

These are not all correct.For example , Sometimes (=  ga 11) represent  RightMouse, other times (=  ga 25).
So I give My question: How can I get the key value of the keyboard and mouse with gread?
I need all the keyboard value(as a,z,etc),mouse value(as  LeftMouse, RightMouse and Wheel) and combination value (as Shift+RightMouse).
I want to know whether This can be achieved or not.
This topic didn't teach me to do that:
http://www.theswamp.org/index.php?topic=12813.0
Sorry for my bad ability of Expression.

pBe

  • Bull Frog
  • Posts: 377
Re: Get the key value of the keyboard and mouse with gread
« Reply #1 on: April 19, 2011, 03:25:25 AM »
A fine example by Lee Mac

Code: [Select]
(defun c:test ( / pt gr code data )

  ;; Define function, localise variables.

  (if

    ;; If the following returns non-nil:

    (setq pt (getpoint "\nSpecify First Point: "))

    ;; Prompt for a point (the base point)
    
    (progn

      ;; Wrap the following statements as one expression
      ;; to be supplied to the IF function as its 'then' argument.
      
      (princ "\nSpecify Next Point: ")

      ;; Print the above message to the user

      (while

        ;; While the following test expression returns true
        
        (progn

          ;; Wrap the following expressions into one expression
          ;; so that it may be passed to the While function as its
          ;; test expression argument.

          ;; Note that *not* all of the expressions within the progn
          ;; statement need to return non-nil, the progn expression
          ;; will only return the value of the last evaluated expression
          ;; this value will then be used to control the While loop.
          
          [color=blue](setq gr (grread t 15 0)

            ;; Monitor user input for every pass of the While loop
            ;; GrRead pauses until it detects user input (you can test
            ;; this by executing a single instance of it at the command
            ;; line), then, when user input is detected it returned a list
            ;; encoding type of input and any data associated with that input.[/color]              
 code (car gr)

       [color=blue]     ;; Get the type of input (e.g. 3=left-click, 5=drag, 2=keyboard...)[/color]
               data (cadr gr)

            ;; Get the value associated with that type of input
          )

          (cond

            ;; Still inside the progn expression (nothing as yet has been passed
            ;; to the While function.

            ;; Here we check the user input detected:
            
            (
             [color=blue] (= 5 code) ;; Mouse has been dragged [/color]
              (redraw)

              ;; Clear the screen
            
              (grdraw  pt data -1)

              ;; Draw a vector from the base point to the current mouse position.
              ;; Vector is drawn in XOR ink (since colour is -1).

              ;; Note that both pt and data are expressed relative to the current UCS
              ;; and that grdraw takes points expressed in UCS.

              t

              ;; At this point, a condition in the COND stament has been evaluated,
              ;; so no other COND statements will be evaluated and whatever is returned
              ;; by this COND expression will be passed to the While loop as a test
              ;; condition.

              ;; We wish to stay in the loop at this point, so we pass a 't' since
              ;; grdraw returns nil.
            )
            (
             [color=blue] (= 2 code) ;; Keyboard has been pressed[/color]
              (alert (strcat "You pressed: " (chr data)))

              ;; Provide an Alert detailing the pressed key.

              t

              ;; Stay in the Loop.
            )
            (
              [color=blue](= 3 code) ;; Left-Click of the mouse[/color]
              (entmakex
                (list
                  (cons 0 "LINE")
                  (cons 10 (trans pt   1 0))
                  (cons 11 (trans data 1 0))
                )
              )

              ;; Create a line from the base point to the clicked point.
              ;; As previously mentioned, both 'pt' and 'data' are expressed
              ;; relative to the current UCS; however, the start and end points
              ;; in the DXF data for a LINE are expressed relative to the WCS.
              ;; Hence a transformation is required, which can be accomplished using
              ;; the trans function.
            
              (setq pt data)

              ;; Set the new base point as the endpoint of the last line created.
              ;; No need for an explicit 't' here, since the above will always
              ;; return a non-nil value and hence keep us in the loop.
            )
          )
          
        ) ;; End Progn

        ;; Note that the While function only has a 'test' expression.
        ;; No other statements are executed within the while loop.
      )
    )
  )

  (redraw) (princ)

  ;; Finally, clear the screen and exit cleanly.
)

I could have sworn i've see a table for values on what key was pressed somewhere... cant quite put my finger on that. but it would be nice to code though  :-)

BTW: 25 for mouse right click

EDIT: see attached file
« Last Edit: April 19, 2011, 03:47:20 AM by pBe »

xiaxiang

  • Guest
Re: Get the key value of the keyboard and mouse with gread
« Reply #2 on: April 19, 2011, 05:05:33 AM »
A fine example by Lee Mac
I could have sworn i've see a table for values on what key was pressed somewhere... cant quite put my finger on that. but it would be nice to code though  :-)
BTW: 25 for mouse right click
EDIT: see attached file
Thanks pBe!
I will read this example Seriously.
It's 11 for mouse right click here.Optical Mouse.Very strange!
BTW:your attached file is downloading slowly for the reason of slow Network speed.
Thanks! It's very useful for me!!!  :angel:

gile

  • Water Moccasin
  • Posts: 2283
  • Marseille, France
Re: Get the key value of the keyboard and mouse with gread
« Reply #3 on: April 19, 2011, 05:09:48 AM »
Hi,

The value returned for a right click (11 or 25) depends on the SHORTCUTMENU sysvar settings.
Speaking English as a French Frog

pBe

  • Bull Frog
  • Posts: 377
Re: Get the key value of the keyboard and mouse with gread
« Reply #4 on: April 19, 2011, 05:19:46 AM »
Hi,

The value returned for a right click (11 or 25) depends on the SHORTCUTMENU sysvar settings.

Thank you for that clarification  gile




kdub

  • Mesozoic keyThumper
  • SuperMod
  • Swamp Rat
  • Posts: 1387
  • class keyThumper<T>:ILazy<T>
Re: Get the key value of the keyboard and mouse with gread
« Reply #5 on: April 19, 2011, 05:20:06 AM »
Hi,

The value returned for a right click (11 or 25) depends on the SHORTCUTMENU sysvar settings.
Excellent investigation gile !
called Kerry in my other life

Sometimes the question is more important than the answer.
#ridesober

xiaxiang

  • Guest
Re: Get the key value of the keyboard and mouse with gread
« Reply #6 on: April 19, 2011, 05:29:06 AM »
Hi pBe
Any suggestion about Key combination (as Shift+Right mouse click)?

xiaxiang

  • Guest
Re: Get the key value of the keyboard and mouse with gread
« Reply #7 on: April 19, 2011, 05:32:36 AM »
Hi,

The value returned for a right click (11 or 25) depends on the SHORTCUTMENU sysvar settings.
Thank you Gile  :-)  :-)  :-)

pBe

  • Bull Frog
  • Posts: 377
Re: Get the key value of the keyboard and mouse with gread
« Reply #8 on: April 19, 2011, 05:36:56 AM »
Hi pBe
Any suggestion about Key combination (as Shift+Right mouse click)?

Not sure.   :|

Anyhoo. heres a more complete list for character code

http://en.wikipedia.org/wiki/ASCII

Maybe you can find it there  :-)

xiaxiang

  • Guest
Re: Get the key value of the keyboard and mouse with gread
« Reply #9 on: April 19, 2011, 05:52:52 AM »
Hi pBe
Any suggestion about Key combination (as Shift+Right mouse click)?
Anyhoo. heres a more complete list for character code
http://en.wikipedia.org/wiki/ASCII
Maybe you can find it there  :-)
Thanks. I will research it . :-)

Lee Mac

  • Seagull
  • Posts: 12514
  • London, England
Re: Get the key value of the keyboard and mouse with gread
« Reply #10 on: April 19, 2011, 07:15:21 AM »
Hi

I don't think Shift / Ctrl can be detected using GrRead, instead you can perhaps use (acet-sys-shift-down) / (acet-sys-control-down).  For some other keys, (acet-sys-keystate <ascii>) may be used. - although consider these are Express Tools functions.

Lee
« Last Edit: April 19, 2011, 07:20:46 AM by Lee Mac »

alanjt

  • Needs a day job
  • Posts: 5340
  • Standby for witty remark...
Re: Get the key value of the keyboard and mouse with gread
« Reply #11 on: April 19, 2011, 08:11:43 AM »
Hi

I don't think Shift / Ctrl can be detected using GrRead, instead you can perhaps use (acet-sys-shift-down) / (acet-sys-control-down).  For some other keys, (acet-sys-keystate <ascii>) may be used. - although consider these are Express Tools functions.

Lee
X2
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

xiaxiang

  • Guest
Re: Get the key value of the keyboard and mouse with gread
« Reply #12 on: April 19, 2011, 08:39:36 PM »
I don't think Shift / Ctrl can be detected using GrRead, instead you can perhaps use (acet-sys-shift-down) / (acet-sys-control-down).  For some other keys, (acet-sys-keystate <ascii>) may be used. - although consider these are Express Tools functions.
Sad...
Must use acet functions...
Using Express Tools support functions can lead to some error in the client's computer that has not been installed Express,so I must explain and clarify to the user of program.
Thanks anyway ,Lee. :-)
And I really get Shift+Right mouse click using the code like my list in this topic:
Code: [Select]
((member gr '((11 1000))) ;;;Shift+RightMouse
And if Ctrl+RightMouse?