Computer Science Canada

The right and left click buttons

Author:  chalcids [ Wed May 30, 2012 7:19 am ]
Post subject:  The right and left click buttons

I want to write a morse code program so when i right click a dash appears and when i left click i get a dot and the well the space bar does a space. I want it to type out messages. Is this possible?

Author:  Raknarg [ Wed May 30, 2012 9:44 am ]
Post subject:  RE:The right and left click buttons

You can look into the Mouse module in the documentation.

Author:  Aange10 [ Wed May 30, 2012 10:16 am ]
Post subject:  RE:The right and left click buttons

It is indeed very possible.

Author:  Raknarg [ Wed May 30, 2012 12:50 pm ]
Post subject:  RE:The right and left click buttons

actually, just to make it simple:

var mx, my, mb : int

Mouse.Where (mx, my, mb)

When you use this code, the procedure will take in three variable and return the mouse's current status. Respectively the x position, y position relative to the screen, and the current button being pressed (0 for none, 1 for left, 10 for middle wheel and 100 for right, I believe)

Author:  chalcids [ Wed May 30, 2012 12:53 pm ]
Post subject:  Re: The right and left click buttons

but what does have to do with the buttons i want it to when i left click in the program to put a dot on the line on the screen like morse code

Author:  Tony [ Wed May 30, 2012 1:28 pm ]
Post subject:  Re: The right and left click buttons

It has to do with the
chalcids @ Wed May 30, 2012 12:53 pm wrote:
i left click

part.

Author:  chalcids [ Wed May 30, 2012 1:47 pm ]
Post subject:  Re: The right and left click buttons

like what is wrong with that part like is there not a button command for that at all

Author:  Tony [ Wed May 30, 2012 2:57 pm ]
Post subject:  RE:The right and left click buttons

That sentence was terrible. Were you trying to ask a question?

Author:  chalcids [ Wed May 30, 2012 3:18 pm ]
Post subject:  Re: The right and left click buttons

i want to know how to use the mouse buttons ie the left click, scroll and right button to do something like when i left click a dot appears when i scroll a space appears and when i right click a - appears.

Author:  Tony [ Wed May 30, 2012 4:20 pm ]
Post subject:  RE:The right and left click buttons

Something like
code:

loop
   get_click_states
   if ( click_states include left_click) then
      draw_dot
   end if
end loop

Author:  chalcids [ Wed May 30, 2012 5:23 pm ]
Post subject:  Re: The right and left click buttons

yeah do you the rest of the code because it says i need to declare some variables?

Author:  Aange10 [ Wed May 30, 2012 5:44 pm ]
Post subject:  Re: The right and left click buttons

chalcids @ 30/5/2012, 4:23 pm wrote:
yeah do you the rest of the code because it says i need to declare some variables?


You need to do the code yourself.

They told you that if you put in three variables to Mouse.Where() that is will respectively output the X,Y, and button states of the mouse.

You were also told that if the button state was 0 then nothing was being pressed, if the state was 1 that it was being left click, if the state was 10 it was being middle clicked, and if the state was 100 it was being right clicked.

So what you've learned:
- How to get the X position of the mouse.
- How to get the Y position of the mouse.
- How to see which button is being pressed.


Now YOU right the code, and if you get stuck we can help. But stuck doesn't mean "Okay I know what i want to do, now tell me how to do everything I don't have."

Author:  chalcids [ Wed May 30, 2012 5:48 pm ]
Post subject:  Re: The right and left click buttons

But why do i need that
Tony gave me what i wanted i just to know how to declare the variables he used.

Author:  Tony [ Wed May 30, 2012 5:57 pm ]
Post subject:  RE:The right and left click buttons

in case that wasn't obvious, none of what I posted was supposed to be working code; it just resembles code to help you read and inspire ideas for how to approach the problem.

You can't just copy-paste blocks of code together, it will not work. Among other reasons, it's an infinite loop and will never give up control to any of the other code you end up pasting in.

Author:  Luffy123 [ Wed May 30, 2012 5:57 pm ]
Post subject:  Re: The right and left click buttons

chalcids @ Wed May 30, 2012 5:48 pm wrote:
But why do i need that
Tony gave me what i wanted i just to know how to declare the variables he used.


He didn't give you anything. Just showed you the format it should be in.

Mouse.Where returns the button that is clicked.

So you should know what you have to do from there. Check what button was clicked and do what you want to do with it.

Author:  chalcids [ Wed May 30, 2012 7:10 pm ]
Post subject:  Re: The right and left click buttons

if i knew how to do that i wouldn't be asking how to do it because there was nothing on what i asked that i learned from that book

Author:  Raknarg [ Wed May 30, 2012 8:10 pm ]
Post subject:  RE:The right and left click buttons

Lets go through it then.

You have a procedure:
Turing:

Mouse.Where (x, y, b)

This procedure will take in three variables that already exist. Lets do that then.
Turing:

var x, y, b : int

loop
     Mouse.Where (x, y, b)
end loop


So now we have a short program where we have a loop that returns the x position, y position and the button state of the mouse.

I've already given you plenty of information, if you dont know where to go from this, I don't really know why you're trying to do something this advanced.

Author:  chalcids [ Wed May 30, 2012 8:15 pm ]
Post subject:  Re: The right and left click buttons

you said this tells me where the mouse is. I am don't care where the cursor is i want to click randomly and a . will appear when i left click and when i right click a - appears and doesn't need that advanced stuff would it?

Author:  Tony [ Wed May 30, 2012 8:48 pm ]
Post subject:  RE:The right and left click buttons

right, but you still need to know if that click has occurred or not. That's what "b" in x,y,b is for.

Author:  Luffy123 [ Wed May 30, 2012 9:11 pm ]
Post subject:  Re: The right and left click buttons

chalcids @ Wed May 30, 2012 8:15 pm wrote:
you said this tells me where the mouse is. I am don't care where the cursor is i want to click randomly and a . will appear when i left click and when i right click a - appears and doesn't need that advanced stuff would it?


You don't have to worry about the variables x, y.

Mouse.Where(x,y,b)

The b is the above method is the button number as in. Right Click, Left Click, Scroll Wheel but the b returns an int value which represents these clicks. So first you have to get the value of b by using this method.

Then check if it's a right click or a left click, and you know how to do this because someone posted in this thread what each click's value is. I don't know the values but you just have to check if b = the click you want's value.

Really I don't think it can get easier then this...

Author:  chalcids [ Thu May 31, 2012 7:30 am ]
Post subject:  Re: The right and left click buttons

okay thanks luffy now i actually understand and thanks to everyone else

Author:  chalcids [ Thu May 31, 2012 7:39 am ]
Post subject:  Re: The right and left click buttons

wait one more issue when i run that code and test the keys the values for my right and left click are both 1 what do i then

Author:  jr5000pwp [ Thu May 31, 2012 7:46 am ]
Post subject:  Re: The right and left click buttons

Somewhere near the top of your code include the line:
code:
Mouse.ButtonChoose ("multibutton")


This allows turing to distinguish between the 3 mouse clicks.


: