# Capture image on custom key combination

**URL:** https://forum.opencv.org/t/capture-image-on-custom-key-combination/16570
**Category:** Python
**Tags:** highgui
**Created:** [February 23, 2024, 9:17am UTC](https://forum.opencv.org/t/capture-image-on-custom-key-combination/16570 "2024-02-23T09:17:48Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![pd3rvr](https://avatars.discourse-cdn.com/v4/letter/p/e95f7d/32.png) [@pd3rvr](https://forum.opencv.org/u/pd3rvr)
#### Post date: [February 23, 2024, 9:17am UTC](https://forum.opencv.org/t/capture-image-on-custom-key-combination/16570/1 "2024-02-23T09:17:48Z")

</div>

I have a short script to start camera on laptop. I want to start to capture image or record only when user customised key combination is used. Can anyone suggest how to get this done ? I have read the cv2.waitkey library but could not get a clear idea of this. See current snippet below;

import cv2

key = cv2. waitKey(1)  
cmra = cv2.VideoCapture(0)  
while True:  
try:  
camera\_avail, frame = cmra.read()  
print(camera\_avail) # true if cmra is running  
print(frame) # matrix values per frame  
cv2.imshow(“streaming frame”, frame)  
key = cv2.waitKey(1)  
print(‘KEY: {}\nORD S: {}’.format(key, ord(‘s’)))  
#print(CHECK)  
if key == ord(‘s’):  
cv2.imwrite(filename=‘rgb\_img.jpg’, img=frame)  
cmra.release()  
img\_new = cv2.imread(‘rgb\_img.jpg’, cv2.IMREAD\_GRAYSCALE)  
img\_new = cv2.imshow(“Captured Image”, img\_new)  
cv2.waitKey(3000)  
cv2.destroyAllWindows()
