Inkey issue in console on rmb

General FreeBASIC programming questions.
UEZ
Posts: 972
Joined: May 05, 2017 19:59
Location: Germany

Inkey issue in console on rmb

Post by UEZ »

When you compile this code as console and press the right mouse bottom inside the console then Inkey starts to return plenty of keystrokes.

Code: Select all

Dim As Long iPosCursor = Csrlin
Dim As String key
Do
	Locate iPosCursor, 1, 0
	key = Inkey()
	? key 
	Select Case key
		Case Chr(27), Chr(113) 'ESC or q to exit program
			Exit Do
	End Select
	Sleep 50
Loop Until False
Is this intended?
grindstone
Posts: 862
Joined: May 05, 2015 5:35
Location: Germany

Re: Inkey issue in console on rmb

Post by grindstone »

I can't reproduce that. Performing any mouse action, nothing happens (just as it ought to be). What OS are you using and what version of FB?
UEZ
Posts: 972
Joined: May 05, 2017 19:59
Location: Germany

Re: Inkey issue in console on rmb

Post by UEZ »

I'm on Win10 but it happens also on Win7.
I took this screenhot as GIF anim:

Image

Sometimes alot of other chars will be printed.

This effect causes my Radio Station tool to drive crazy because of all the keystrokes. :-)
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: Inkey issue in console on rmb

Post by D.J.Peters »

same here on Windows 10

Joshy
Last edited by D.J.Peters on Mar 30, 2021 9:38, edited 1 time in total.
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: Inkey issue in console on rmb

Post by D.J.Peters »

I got it it prints last stuff from clipboard !

It's a console feature for example you can copy a long path and than in the console type a command and press the right mouse button.

cd [right mouse click]

cd https://www.freebasic.net/forum/

As a work around at start clear the clipboard via WINDOWS API.

Joshy
Last edited by D.J.Peters on Mar 30, 2021 9:39, edited 1 time in total.
fxm
Moderator
Posts: 12081
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Inkey issue in console on rmb

Post by fxm »

It depends on "Quick Edit" Mode in window properties : ON or OFF
dodicat
Posts: 7976
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Inkey issue in console on rmb

Post by dodicat »

I got the repeat keys also.
win10
fb 1.07.2
64 bits
If you right click the console the clipboard gets pasted to it (as D.J.Peters says), on win 10 anyway.

If you do this just before the do loop, it should clear the clipboard
shell "cmd/c echo.|clip"
UEZ
Posts: 972
Joined: May 05, 2017 19:59
Location: Germany

Re: Inkey issue in console on rmb

Post by UEZ »

Oh my God, of course it pastes the stuff from the clipboard to the console. Image

I just wondered why it is different but it depends on what is in the clipboard.

Thx.
grindstone
Posts: 862
Joined: May 05, 2015 5:35
Location: Germany

Re: Inkey issue in console on rmb

Post by grindstone »

Same behaviour on WinXP if "Quick Edit" is on (switched off by default here). Very funny!
UEZ
Posts: 972
Joined: May 05, 2017 19:59
Location: Germany

Re: Inkey issue in console on rmb

Post by UEZ »

You can disable it e.g. this code:

Code: Select all

#Include "windows.bi"
Dim As DWORD cmode
Dim As HANDLE hInput = GetStdHandle(STD_INPUT_HANDLE)
GetConsoleMode(hInput, @cmode)
SetConsoleMode(hInput, ENABLE_EXTENDED_FLAGS Or (cmode And Not ENABLE_QUICK_EDIT_MODE))

? "Press right mouse bottom"
Dim As Long iPosCursor = Csrlin
Dim As String key
Do
	Locate iPosCursor, 1, 0
	key = Inkey()
	? key
	Select Case key
		Case Chr(27), Chr(113) 'ESC or q to exit program
			Exit Do
	End Select
	Sleep 50
Loop Until False

SetConsoleMode(hInput, cmode)
Tested on Win10 only.
grindstone
Posts: 862
Joined: May 05, 2015 5:35
Location: Germany

Re: Inkey issue in console on rmb

Post by grindstone »

Works also on XP.
UEZ
Posts: 972
Joined: May 05, 2017 19:59
Location: Germany

Re: Inkey issue in console on rmb

Post by UEZ »

Any idea how to block the context menu when pressing the rmb on the console window?

Code: Select all

#Include "windows.bi"

Sub SetConsoleSize(cols As Long, lines As Long)
    Shell "MODE CON: COLS=" + Str(cols) + "LINES=" + Str(lines)
End Sub

Dim As DWORD cmode
Dim As HANDLE hInput = GetStdHandle(STD_INPUT_HANDLE)
GetConsoleMode(hInput, @cmode)
SetConsoleMode(hInput, ENABLE_EXTENDED_FLAGS Or (cmode And Not ENABLE_QUICK_EDIT_MODE))
SetConsoleSize(90, 8)

? "Press right mouse bottom"
Dim As Long iPosCursor = Csrlin
Dim As String key
Do
	Locate iPosCursor, 1, 0
	key = Inkey()
	? key
	Select Case key
		Case Chr(27), Chr(113) 'ESC or q to exit program
			Exit Do
	End Select
	Sleep 50
Loop Until False

SetConsoleMode(hInput, cmode)
Thx.
dodicat
Posts: 7976
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Inkey issue in console on rmb

Post by dodicat »

Tis one seems to do it.

Code: Select all

Sub SetConsoleSize(cols As Long, lines As Long)
    Shell "MODE CON: COLS=" + Str(cols) + "LINES=" + Str(lines)
End Sub


SetConsoleSize(90, 8)
shell "cmd/c echo.|clip"

Dim As Long iPosCursor = Csrlin
Dim As String key
Do
   Locate iPosCursor, 1, 0
   key = Inkey()
   ? key
   Select Case key
      Case Chr(27), Chr(113) 'ESC or q to exit program
         Exit Do
   End Select
   Sleep 50
Loop Until False 
UEZ
Posts: 972
Joined: May 05, 2017 19:59
Location: Germany

Re: Inkey issue in console on rmb

Post by UEZ »

Thanks dodicat but it works a long as you don't have anything in the clipboard. After the code is started and you put something to the clipboard you can paste it again.
Further, I don't want to clear the clipboard because maybe the data is needed.
dodicat
Posts: 7976
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Inkey issue in console on rmb

Post by dodicat »

Maybe simplify a bit.

Code: Select all

#include "windows.bi"

Sub SetConsoleSize(cols As Long, lines As Long)
    Shell "MODE CON: COLS=" + Str(cols) + "LINES=" + Str(lines)
End Sub

SetConsoleSize(90, 8)

    dim as any ptr h
    dim as long DefaultMode
    GetConsoleMode(h, @DefaultMode) 
    SetConsoleMode(h, DefaultMode and not  ENABLE_QUICK_EDIT_MODE)


Dim As Long iPosCursor = Csrlin
Dim As String key
Do
   Locate iPosCursor, 1, 0
   key = Inkey()
   ? key
   Select Case key
      Case Chr(27), Chr(113) 'ESC or q to exit program
         Exit Do
   End Select
   Sleep 50
Loop Until False
SetConsoleMode(h, DefaultMode) 
Post Reply