# Activate webcam x seconds after mouse is pressed (frameCount)

**URL:** <https://discourse.processing.org/t/activate-webcam-x-seconds-after-mouse-is-pressed-framecount/30585>\
**Category:** Coding Questions\
**Created:** [June 8, 2021, 8:19pm UTC](https://discourse.processing.org/t/activate-webcam-x-seconds-after-mouse-is-pressed-framecount/30585 "2021-06-08T20:19:05Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![saskia\_NL](https://avatars.discourse-cdn.com/v4/letter/s/8baadc/32.png) [@saskia\_NL](https://discourse.processing.org/u/saskia_NL)\
**Post date:** [June 8, 2021, 8:19pm UTC](https://discourse.processing.org/t/activate-webcam-x-seconds-after-mouse-is-pressed-framecount/30585/1 "2021-06-08T20:19:05Z")

</div>

Hi all,

I want to play a video and a few seconds into the video, I want the webcam to activate for 5 seconds and disappear again. I got it working to the point where the video plays and the webcam activates after 600 frames, but I want the webcam to activate 600 frames AFTER the mousePressed.  
Is there a way I can count from the point the mouse is pressed?  
This is my code so far:

```auto
let vid;
var cap;

function setup() {
  createCanvas(1920,1080);
  vid = createVideo("testVid.mp4"); 
  vid.hide();
  cap = createCapture(VIDEO);
  cap.hide();
}

function draw() {
  background(0);
  image(vid, 10, 10);
  if (frameCount > 600){
    image(cap,100,100, 320, 240);
}
 if (frameCount > 900){
   cap.hide();
 image (vid, 0,0);
 }
}

function mousePressed() {
  vid.loop(); 
  
}

```

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [June 8, 2021, 9:03pm UTC](https://discourse.processing.org/t/activate-webcam-x-seconds-after-mouse-is-pressed-framecount/30585/2 "2021-06-08T21:03:32Z")

</div>

> [@saskia\_NL](#):
>
> Is there a way I can count from the point the mouse is pressed?

global var: int frameMouse=-1;

in mousePressed function : frameMouse= frameCount ;

then in draw() say `if (frameCount - frameMouse > 600 && frameMouse>0) ....`
