Close window

New to FreeBASIC? Post your questions here.
Post Reply
amigainspired
Posts: 17
Joined: Mar 15, 2010 19:44
Location: Pilsen, Czech Republic

Close window

Post by amigainspired »

Hallo.
I have one specific problem with loop. I need close window by red cross (right up), but in the loop DO-LOOP is not working...

Code: Select all

do
  getmouse x,y,,b

if x>15 and x<50 then exit do

loop
Loop working good, but red cross is out of service.

Thank you beforehand!

P.S.Sorry for terrible english! :(
JasonL
Posts: 11
Joined: Sep 27, 2011 17:21
Location: Essex, UK

Loop 'X' issues

Post by JasonL »

Seems to me that your loop is looping and not reading the next message from your preferred GUI messaging system.

Without checking these messages (they are ignored) and not action is taken....?


Just a thought.
fxm
Moderator
Posts: 12516
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Post by fxm »

in windowed mode, clicking on the window close button will add a keypress of Chr(255)&"k" to the Inkey buffer.
You must test it as a key in:
do
getmouse x,y,,b
.....
loop until inkey = chr(255)&"k"
amigainspired
Posts: 17
Joined: Mar 15, 2010 19:44
Location: Pilsen, Czech Republic

Post by amigainspired »

fxm wrote:in windowed mode, clicking on the window close button will add a keypress of Chr(255)&"k" to the Inkey buffer.
You must test it as a key in:
do
getmouse x,y,,b
.....
loop until inkey = chr(255)&"k"
Yes, this is exactly what I need! ;-) Thanks!

What is "k" (or &"k" with chr$(255)) actually? And exists, for example, chr$ for key ENTER?
fxm
Moderator
Posts: 12516
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Post by fxm »

If the key is an "extended" one (numeric pad, cursors, functions, close button) a two-character String is returned, the first of which is the extended character:
Chr(255), except Chr(0) for QB dialect.

RETURN key enters Chr(13) in the Inkey buffer.
amigainspired
Posts: 17
Joined: Mar 15, 2010 19:44
Location: Pilsen, Czech Republic

Post by amigainspired »

fxm wrote:If the key is an "extended" one (numeric pad, cursors, functions, close button) a two-character String is returned, the first of which is the extended character:
Chr(255), except Chr(0) for QB dialect.

RETURN key enters Chr(13) in the Inkey buffer.
Thank you very much!! ;-)
pestery
Posts: 493
Joined: Jun 16, 2007 2:00
Location: Australia

Post by pestery »

The escape key is 27.
Also, for the close window button you could use Chr(255,107) instead of Chr(255)&"k". They both do the same thing.

Here is a little program I used to use to find key ID numbers. You might find it useful, just press random keys and see their IDs. Press Space to exit.

Code: Select all

ScreenRes 320, 240
Dim As String key
Do
   Sleep 16
   key = InKey
   While key <> ""
      For i As Integer = 0 To (Len(key) - 1)
         Print " " & key[i];
      Next
      Print
      If key = " " Then Exit Do
      key = InKey
   Wend
Loop
On a side note, you may want to investigate MultiKey and ScreenEvent if you haven't used them before. From your original question I think you might find them useful.
http://www.freebasic.net/wiki/wikka.php ... PgMultikey
http://www.freebasic.net/wiki/wikka.php ... creenevent
amigainspired
Posts: 17
Joined: Mar 15, 2010 19:44
Location: Pilsen, Czech Republic

Post by amigainspired »

pestery wrote:The escape key is 27.
Also, for the close window button you could use Chr(255,107) instead of Chr(255)&"k". They both do the same thing.

Here is a little program I used to use to find key ID numbers. You might find it useful, just press random keys and see their IDs. Press Space to exit.

Code: Select all

ScreenRes 320, 240
Dim As String key
Do
   Sleep 16
   key = InKey
   While key <> ""
      For i As Integer = 0 To (Len(key) - 1)
         Print " " & key[i];
      Next
      Print
      If key = " " Then Exit Do
      key = InKey
   Wend
Loop
On a side note, you may want to investigate MultiKey and ScreenEvent if you haven't used them before. From your original question I think you might find them useful.
http://www.freebasic.net/wiki/wikka.php ... PgMultikey
http://www.freebasic.net/wiki/wikka.php ... creenevent

wau, thanks, it is comprehensive information. It is very importat for work with keyboard & mouse. I did not know about use chr$(X,Y).
Post Reply