mouse3.pp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. {example for GetMouseState, IsLPressed, IsRPressed and IsMPressed}
  2. Uses MsMouse, Crt;
  3. Var X, Y, State: Longint;
  4. Begin
  5. If MouseFound Then
  6. Begin
  7. ClrScr;
  8. ShowMouse;
  9. GotoXY(5,24);
  10. Write('Left button:');
  11. GotoXY(30,24);
  12. Write('Right button:');
  13. GotoXY(55,24);
  14. Write('Middle button:');
  15. While KeyPressed do Readkey; {clear keyboard buffer}
  16. Repeat
  17. GetMouseState(x, y, State);
  18. GotoXY(20, 22);
  19. Write('X: ',x:5,' (column: ',(x div 8):2,') Y: ',y:5, ' (row: ',(y div 8):2,')');
  20. GotoXY(18, 24); {left button}
  21. If (State and LButton) = LButton Then
  22. {or: "If LPressed Then". If you use this function, no call to GetMouseState
  23. is necessary}
  24. Write('Down')
  25. Else
  26. Write('Up ');
  27. GotoXY(44, 24); {right button}
  28. If (State and RButton) = RButton Then
  29. {or: "If RPressed Then"}
  30. Write('Down')
  31. Else
  32. Write('Up ');
  33. GotoXY(70, 24); {middle button}
  34. If (State and MButton) = MButton Then
  35. {or: "If MPressed Then"}
  36. Write('Down')
  37. Else
  38. Write('Up ')
  39. Until KeyPressed;
  40. HideMouse;
  41. While KeyPressed Do Readkey
  42. End
  43. End.