keystroke detection

Discussions related to mouse, keyboard, fonts and Graphical User Interface
Posts: 53
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


User avatar
Posts: 95
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

        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.



Posts: 198
Joined: Mon 02 Apr 2018, 18:04

Re: keystroke detection

Post by DDRM »

This seems to work fine:

Code: Select all

        WAIT 1
        MOUSE x%,y%,z%
        PRINT x%,y%
        IF INKEY(-67) THEN PRINT "X down"
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,


Posts: 143
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.