View Full Version : Mouse Events in Console
MouseTrap
17-02-2009, 07:40
When i run the sample script "Console_Inkey.tbasic" the mouse move event keeps firing every second even when no mouse movement is occurring.
Also the Y value gotten from console_inkey command keeps incrementing by 1 every time. outputting something like this:
You moved the mouse to 22,42
You moved the mouse to 22,43
You moved the mouse to 22,44
You moved the mouse to 22,45
You moved the mouse to 22,46
You moved the mouse to 22,47
You moved the mouse to 22,48
You moved the mouse to 22,49
this Y value will eventually increment beyond 255 and flip back to 0. still while the mouse is never touched.
Is there a more reliable way to get mouse events from the console?
Thanks
ErosOlmi
17-02-2009, 08:43
A console window can have a screen buffer that goes far from the current visible console window. So at every PRINTL the Y position will increment continuously.
Just add the following line at the beginning and you will have a fixed console buffer:
Console_SetScreenBufferSize(80, 25)
Change console buffer as you prefer.
Console_InKey is very reliable as far as I know. I've double checked here under different OS, and in all my tests mouse events are fired only when mouse is moved.
What OS are you using? Are you using special mouse or tablet input?
Do you have some special driver or special config in your computer?
Eros
MouseTrap
17-02-2009, 09:33
Your definitely right about the buffer. That fixed the issue with mouse coords.
Im using Winxp sp2 and average microsoft infrared mouse. Im not using any special driver and don't have any exotic hardware like usb devices ect.
I suppose I could just look for mouse delta-movements and use the 'GetCursor' commands when I trap a button hit.
Thanks!
ErosOlmi
17-02-2009, 11:03
Ok thanks. Can you please confirm you are using current latest thinBasic version 1.7.6.0 downloaded from official thinBasic web site?
Can someone else help here and confirm if the mentioned script behave correctly or not? It would help a lot.
Correct mouse events should be fired only if mouse is over the console window and it is moving.
_________________________________________________
Console_Inkey (http://www.thinbasic.com/public/products/thinBasic/help/html/console_inkey.htm) returns a string.
If the string len is = 3 it means it is a mouse event. The 3rd char of this string gives the console mouse event type (http://www.thinbasic.com/public/products/thinBasic/help/html/consoleequates.htm).
Thanks a lot
Eros
Petr Schreiber
17-02-2009, 11:31
Hi Eros,
I have ball mouse from Microsoft ( the first one with wheel :D ) and no problem - it fires "event" only when I move it.
With no locked buffer, during movmement the Y grows to 255 and then flips back to 0
With locked buffer it simply shows "normal" coordinates.
My brother had laser mouse, and it sometimes did wild things when on bad pad. It is possible laser mouse sensor is observing microscopic movements / false positives which are so small cursor does not move but mouse sends info anyway?
Petr
ErosOlmi
17-02-2009, 13:06
Yes, Console_Inkey returns even if micro movements are made. For my tests I have only laser mouse.
Translated to single char console movements (on console mouse is simulated by a single char), cursor position x and y will not change of course.
I suppose in Console applications it is more important to get mouse clicks or double clicks instead of mouse movements. But of course it it depend program by program.
In any case you confirmed that Console_Inkey is working fine. And that was my point.
So we need to understand why for MouseTrap (your forum name is appropriated for this post :D ) things are going in a different way.
MouseTrap, did you executed exactly the script example coming from official installation or you have a executed a modified one?
Ciao
Eros
MouseTrap
17-02-2009, 17:40
MouseTrap, did you executed exactly the script example coming from official installation or you have a executed a modified one?
I first noticed it in my own script and then confirmed with the "Console_Inkey.tbasic" script from the samples. (unmodified)
Just to clarify:
1)I'm not touching the mouse in any way.
2)I suspected maybe a slight vibration from my desk, but hitting my desk to induce a vibration doesnt seem to create more events.
3)When i intentionally make micro adjustments to the mouse i will get a diff coord returned. When its happening by itself, its the same coord returned repeatedly.
With the tip you gave me about the buffer issue. that resolves most of my concern. The timing of the repeated events seems very non-deterministic. I wouldn't spend a lot of effort with the repeating coords because it could be a hardware issue.
Its easy to copy the coords to local variables and only care when the coords from 'Console_Inkey' differ from locals. In that case i don't have any issue with the mouse+console.
Thanks
ErosOlmi
17-02-2009, 17:57
Ok MouseTrap.
I just wanted to be sure it would not be a real bug. I tested on 3 different virtual machines and 4 different physical computers and I was not able to replicate the exact problem you reported. Here console Mouse events are fired only when mouse is over the console window and mouse is moving.
Anyhow, feel free to report again this behaves if you think it can be a bug and we will investigate further.
Ciao
Eros
Eros --
FYI the Console_Inkey demo script works fine here for me.
I am using a cordless Logitec laser mouse connected to XP Sp2 system via the USB.
Don
ErosOlmi
17-02-2009, 18:53
Thanks Don.
Michael Hartlef
17-02-2009, 21:32
Hi folks, script works fine here too. MouseTrap, do you have a ball mouse or a led mouse? Later ones can be affected by light rays from your environment. I noticed this with my old logitech mouse sometimes. Even no one touched the mouse, the cursor was moving.
RobertoBianchi
18-02-2009, 12:19
Hello MouseTrap,
did you tried to change the mouse (and/or port) and run the script again?
The Console_InKey() function was build using WIN32 standard API so I'm really not expecting this oddity behaviour.
Thank you very much and best regards,
Roberto
ReneMiner
04-05-2013, 13:06
It's an older thread but I append this here to keep the informations together:
What parameters give information about mousewheel-delta - so how many ticks up or down?
ReneMiner
05-07-2013, 14:06
push up again- still same question:
is there a possibility to get direction of mousewheel?
Uses "Console"
Dim s As String
Dim i As Long
PrintL "Please press 'q' to exit."
Do
s = Console_InKey()
sleep(0)
i = len(s)
select case i
case 1
PrintL "You pressed the " + s + " key."
case 2
Print "You pressed an extended key: " + Hex$(Asc(s, 2))
'--Check second char of returned string
Select Case Asc(s, 2)
Case %VK_OEM_PLUS
PrintL " + (plus)"
Case %VK_OEM_COMMA
PrintL " , (comma)"
Case %VK_OEM_MINUS
PrintL " - (minus)"
Case %VK_OEM_PERIOD
PrintL " . (period)"
Case Else
PrintL " ... something else"
End Select
case 3
Select Case Asc(RIGHT$(s, 1))
case %CONSOLE_MOUSE_MOVED
PrintL "You moved the mouse to" + Str$(Asc(LEFT$(s,1))) + "," + LTrim$(Str$(Asc(Mid$(s, 2,1))))
case %CONSOLE_DOUBLE_CLICK
PrintL "You double clicked to" + Str$(Asc(LEFT$(s,1))) + "," + LTrim$(Str$(Asc(Mid$(s, 2,1))))
case %CONSOLE_LBUTTON
PrintL "You pressed the left button"
case %CONSOLE_RBUTTON
PrintL "You pressed the right button"
case %CONSOLE_MBUTTON
PrintL "You pressed the middle button"
case %CONSOLE_MOUSE_WHEELED
PrintL "Mouse wheeled"
End Select
end select
LOOP UNTIL (i OR s = "q")
Petr Schreiber
05-07-2013, 17:21
Hi Rene,
I think it is not possible using current version of the Console module, but maybe you could suggest it as feature - it should be doable with help of API function.
ReadConsoleInput (http://msdn.microsoft.com/en-us/library/windows/desktop/ms684961%28v=vs.85%29.aspx) > INPUT_RECORD (http://msdn.microsoft.com/en-us/library/windows/desktop/ms683499%28v=vs.85%29.aspx) structure > MOUSE_EVENT_RECORD (http://msdn.microsoft.com/en-us/library/windows/desktop/ms684239%28v=vs.85%29.aspx) substructure, because they say the following for MOUSE_WHEELED:
If the high word of the dwButtonState member contains a positive value, the wheel was rotated forward, away from the user. Otherwise, the wheel was rotated backward, toward the user.
Petr