Where the Arrows are

General FreeBASIC programming questions.
Post Reply
Jerry Fielden
Posts: 165
Joined: May 27, 2005 14:14
Location: Marshall, Oklahoma, USA
Contact:

Where the Arrows are

Post by Jerry Fielden »

Here's something thats a little funny that deals with Inkey and the Mouse cursor.


Mouse and Inkey In Console Screen Mode 0.

If I make an area of my screen Mouse click on sensitive and when I left click on that area, the program is instructed to do something. That works alright.

Now if I by accident happen to have my Mouse cursor resting on that sensitive area, and I start typing something in an another area of the Screen below it using Inkey$, the Mouse sensitive area becomes activated as if I clicked the Left Mouse button. I have to make sure where my mouse arrow is resting before I can start typing.

Now if I type something above that sensitive area, it doesn't do that. It will go ahead and put the characters on the screen without clicking the left mouse button when I hit a key.

This is happening to me in XP Home, Windowed, Console mode 0.
Antoni
Posts: 1393
Joined: May 27, 2005 15:40
Location: Barcelona, Spain

Post by Antoni »

I tried this and I have no change in the button state when pressing keys.

Code: Select all

do
getmouse x,y,w,b
locate 1,1
print x,y,w,b
k$=inkey$
loop until k$=chr$(27)
But you mention a sensitive area, so I guess your code is more complicated than mine....Code, please?
Jerry Fielden
Posts: 165
Joined: May 27, 2005 14:14
Location: Marshall, Oklahoma, USA
Contact:

Post by Jerry Fielden »

Place the mouse cursor in the little box and start hitting on different keys. To me, it acts the save as clicking on it with the left mouse button.

Code: Select all


  Sub GetKeys (Keynumber As Integer, k As String, Rgt As Integer, _
              Lft As Integer,  cRow As Integer, cCol As Integer)
    Dim buttons As Integer         
    Keynumber=0 : Rgt=0 : Lft=0 : cRow=0 : cCol=0  
    Locate 1, 1, 0   
    Do
        GetMouse cCol, cRow,, buttons
        If buttons And 1 Then lft = 1 : Exit Sub
        If buttons And 2 Then Rgt = 1 : Exit Sub 
        k = Inkey$
        Sleep 1 
    Loop While k = ""
    If Asc(k) > 31 And Asc(k) < 127 Then 
        keynumber = Asc(k)
    ElseIf Asc(k) = 27 Then
        keynumber = 27
    ElseIf Asc(k) = 8 Then
        keynumber = 8
    ElseIf Asc(k) = 9 Then
        keynumber = 9
    ElseIf Asc(k) = 13 Then
        keynumber = 13    
    Else 
        keynumber = Cvi(k +k+ k+k) : Sleep 10     'Fm examples
    End If 
    
 End Sub
 
  
Color 8, 7
For x% = 10 To 13
   Locate x%, 20 : Print Space$(20)         ' Color Mouse clicking area 
Next 


Do   

    GetKeys Kn%, Ky$ , Rt%, Lt%, row%, col%                                                     
    
    Color 7, 0
    
    Ke$ = UCase$(Ky$)
    If lt% <> 0  Or Ke$ <> "" Then
      If Ke$ = "B" Or (Row% > 8 And Row% < 14 And Col% > 19 And Col% < 41) Then          ' check if mouse in area
         Print " You clicked on Mouse area " 
         Sleep 1000 : Locate 1, 1 : Color 7, 0 : Print Space$(30) 
      Else 
         Locate 20, 20
         Print "You hit the "; Ke$; " Key"
      End If
   End If
    
Loop Until Kn% = 27
 
cha0s
Site Admin
Posts: 5319
Joined: May 27, 2005 6:42
Location: USA
Contact:

Post by cha0s »

follow this path

Ke$ = UCase$(Ky$)
If lt% <> 0 Or Ke$ <> "" Then
If Ke$ = "B" Or (Row% > 8 And Row% < 14 And Col% > 19 And Col% < 41) Then ' check if mouse in area
Print " You clicked on Mouse area "
Sleep 1000 : Locate 1, 1 : Color 7, 0 : Print Space$(30)
Else
Locate 20, 20
Print "You hit the "; Ke$; " Key"
End If
End If


=)
MichaelW
Posts: 3500
Joined: May 16, 2006 22:34
Location: USA

Post by MichaelW »

Hi Jerry,

Row% and Col% are set regardless of the state of the mouse buttons. I think you need include the state of the mouse button in your “If Ke$ =” statement.
Jerry Fielden
Posts: 165
Joined: May 27, 2005 14:14
Location: Marshall, Oklahoma, USA
Contact:

Post by Jerry Fielden »

Hello Michael,

This is only a shorten example to show what it was doing.

Adding the Lt% to the Ke$ line does the trick, but.......

I was trying to get by with one Lt in the place of 12 Lts, since I have 12 buttons with character Hotkeys in case somebody didn't like using the Mouse.

But, it does work that way, thanks.

I coded it the same way with another compiler and it didn't cause those effects. So I thought it might be something that somebody would want to fix.

Later.......Jerry Fielden
cha0s
Site Admin
Posts: 5319
Joined: May 27, 2005 6:42
Location: USA
Contact:

Post by cha0s »

I guess you didn't understand my post. Because of the "or", execution will always fall through. Just a little change in logic:

Code: Select all

    Ke$ = UCase$(Ky$) 
    If (lt% <> 0 Or Ke$ = "B") And (Row% > 8 And Row% < 14 And Col% > 19 And Col% < 41) Then          ' check if mouse in area 
         Print " You clicked on Mouse area " 
         Sleep 1000 : Locate 1, 1 : Color 7, 0 : Print Space$(30) 
    ElseIf Ke$ <> "" Then 
         Locate 20, 20 
         Print "You hit the "; Ke$; " Key" 
   End If 

I assumed by your example that you intended to have "B" as a mouse button key.
Jerry Fielden
Posts: 165
Joined: May 27, 2005 14:14
Location: Marshall, Oklahoma, USA
Contact:

Post by Jerry Fielden »

Chaos,

That works also chaos, thanks
Yeah, the B was for keyboard hits.

Later.........Jerry Fielden
Post Reply