In some games, if you press 1, it switches to pistol, then you let go, then you can click to fire. If you press 2, it switches to sniper, then let go, then you click to fire.
How do I simulate that?
Develop games in your browser. Powerful, performant & highly capable.
What you can do is spawn a pistol sprite or play the pistol animation when 1 is pressed and then test for if the sprite is on screen or the animation playing when the mouse is clicked, from that you can fire the gun. Same with sniper, spawn or start animation when 2 is pressed and then test for if the sniper is on when you click.
Here is an old capx I made for a different but similar question. It does what you want but in it you click the gun picture instead of pushing 1 or 2.. same principle. Click on (A) "button" to fire.
https://drive.google.com/open?id=0Bx-ufu2WID53MWFjT2owWEVEWHc (click the download arrow in upper right corner to download).
Thanks to both!