Guest User

Untitled

a guest
Jul 18th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. protected override void Initialize()
  2. {
  3. // Make mouse visible
  4. this.IsMouseVisible = true;
  5.  
  6. base.Initialize();
  7. }
  8.  
  9. MouseState mouseStateCurrent, mouseStatePrevious;
  10.  
  11. protected override void Update(GameTime gameTime)
  12. {
  13. // Allows the game to exit
  14. if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
  15. {
  16. this.Exit();
  17. }
  18.  
  19. // Get current mouseState
  20. mouseStateCurrent = Mouse.GetState();
  21.  
  22. // Left MouseClick
  23. if (mouseStateCurrent.LeftButton == ButtonState.Pressed)
  24. {
  25. // TODO when left mousebutton clicked
  26. }
  27.  
  28. // Right MouseClick
  29. if (mouseStateCurrent.RightButton == ButtonState.Pressed && mouseStatePrevious.RightButton == ButtonState.Released)
  30. {
  31. //TODO when right mousebutton clicked
  32. }
  33.  
  34. mouseStatePrevious = mouseStateCurrent;
  35.  
  36.  
  37. // Update
  38. base.Update(gameTime);
  39. }
  40.  
  41. enum CLICKS{left=0, right, middle);
  42. public void mouseClick(){
  43. mouseClick(-1);
  44. }
  45.  
  46. public void mouseClick(int manualClick){
  47.  
  48. if(mouseStateCurrent.LeftButton == ButtonState.Pressed || manualClick == CLICKS.left)
  49. leftClick();
  50.  
  51. }
  52.  
  53. public void leftClick(){
  54. //do stuff
  55. }
  56.  
  57. public void randomFunction(){
  58. //doing stuff
  59. mouseClick(CLICKS.left); //<-- will simulate a left click
  60. }
Add Comment
Please, Sign In to add comment