keystroke detection

Discussions related to mouse, keyboard, fonts and Graphical User Interface
Ric
Posts: 51
Joined: Tue 17 Apr 2018, 21:03

keystroke detection

Post by Ric »

If i wish to detect a key stroke at the same time as the mouse movement, if i choose a key such as "shift", this is possible by using INKEY(minus argumant). But if i try this with a lettered key, when i hold down say "X" then the MOUSE x,y,b seems to do nothing and thus the two can not be detected together. Am i doing something wrong or is in not possible to do what i want.

I would like to hold down various keys and then with the mouse movement make different things happen.

Here's hoping

Ric

User avatar
hellomike
Posts: 89
Joined: Sat 09 Jun 2018, 09:47

Re: keystroke detection

Post by hellomike »

Hi Ric,

Not sure what you tried but when I run the following:

Code: Select all

      REPEAT
        WAIT 0
        MOUSE X%,Y%,B%
        IF B% IF INKEY(-1) N%+=1 : PRINT "Mouse clicked AND <shift> pressed... ";N%
      UNTIL 0
It will print text only when both a <shift> key is pressed and a mouse button is clicked.

Regards,

Mike

DDRM
Posts: 175
Joined: Mon 02 Apr 2018, 18:04

Re: keystroke detection

Post by DDRM »

This seems to work fine:

Code: Select all

      REPEAT
        WAIT 1
        MOUSE x%,y%,z%
        PRINT x%,y%
        IF INKEY(-67) THEN PRINT "X down"
      UNTIL FALSE
The x,y coordinates of the mouse seem to continue to change even while the X is pressed - so presumably I'm misunderstanding your problem. Can you post a brief example of your code, and explain what it doesn't do that you want it to?

Best wishes,

D

KenDown
Posts: 141
Joined: Wed 04 Apr 2018, 06:36

Re: keystroke detection

Post by KenDown »

It should be noted that ON MOUSE provides a way of telling whether SHIFT or CTRL are held down (see the help files for details). However for other keys you will have to use a negative inkey to test for the specific key. This can be a nuisance if you have half a dozen keys that need to be checked, but I don't know of any other method.