Skip to content

Commit c70aea7

Browse files
committed
add waitKeyEx method
Needed on windows (and maybe other systems?) to capture special buttons (like arrow keys).
1 parent 0c89c33 commit c70aea7

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

cc/io/io.cc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ NAN_MODULE_INIT(Io::Init) {
1616
Nan::SetMethod(target, "imshowWait", ImshowWait);
1717
Nan::SetMethod(target, "imwrite", Imwrite);
1818
Nan::SetMethod(target, "waitKey", WaitKey);
19+
Nan::SetMethod(target, "waitKeyEx", WaitKeyEx);
1920
Nan::SetMethod(target, "imencode", Imencode);
2021
Nan::SetMethod(target, "imdecode", Imdecode);
2122
Nan::SetMethod(target, "moveWindow", MoveWindow);
@@ -105,6 +106,16 @@ NAN_METHOD(Io::WaitKey) {
105106
info.GetReturnValue().Set(Nan::New(key));
106107
}
107108

109+
NAN_METHOD(Io::WaitKeyEx) {
110+
int key;
111+
if (info[0]->IsNumber()) {
112+
key = cv::waitKeyEx(info[0]->ToNumber(Nan::GetCurrentContext()).ToLocalChecked()->Value());
113+
} else{
114+
key = cv::waitKeyEx();
115+
}
116+
info.GetReturnValue().Set(Nan::New(key));
117+
}
118+
108119
NAN_METHOD(Io::MoveWindow) {
109120
FF::TryCatch tryCatch("Io::MoveWindow");
110121
std::string winName;

cc/io/io.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class Io {
1616
static NAN_METHOD(Imshow);
1717
static NAN_METHOD(ImshowWait);
1818
static NAN_METHOD(WaitKey);
19+
static NAN_METHOD(WaitKeyEx);
1920
static NAN_METHOD(MoveWindow);
2021
static NAN_METHOD(DestroyWindow);
2122
static NAN_METHOD(DestroyAllWindows);
@@ -29,4 +30,4 @@ class Io {
2930
static NAN_METHOD(ImdecodeAsync);
3031
};
3132

32-
#endif
33+
#endif

lib/typings/cv.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ export function transformAsync(mat: Mat, m: Mat): Promise<Mat>;
205205
export function undistortPoints(srcPoints: Point2[], cameraMatrix: Mat, distCoeffs: Mat): Point2[];
206206
export function undistortPointsAsync(srcPoints: Point2[], cameraMatrix: Mat, distCoeffs: Mat): Promise<Point2[]>;
207207
export function waitKey(delay?: number): number;
208+
export function waitKeyEx(delay?: number): number;
208209

209210
export type DrawParams = {
210211
thickness?: number;

0 commit comments

Comments
 (0)