Skip to content

Commit

Permalink
added window pollkey function (#1198)
Browse files Browse the repository at this point in the history
  • Loading branch information
diegohce authored Aug 14, 2024
1 parent 505eaf0 commit 41ec753
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 0 deletions.
4 changes: 4 additions & 0 deletions highgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ int Window_WaitKeyEx(int delay = 0) {
return cv::waitKeyEx(delay);
}

int Window_PollKey(void) {
return cv::pollKey();
}

void Window_Move(const char* winname, int x, int y) {
cv::moveWindow(winname, x, y);
}
Expand Down
19 changes: 19 additions & 0 deletions highgui.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,25 @@ func (w *Window) WaitKeyEx(delay int) int {
return int(C.Window_WaitKey(C.int(delay)))
}

// PollKey polls for a pressed key.
// The function pollKey polls for a key event without waiting.
// It returns the code of the pressed key or -1 if no key was pressed since
// the last invocation. To wait until a key was pressed, use waitKey.
//
// The functions waitKey and pollKey are the only methods in HighGUI that can
// fetch and handle GUI events, so one of them needs to be called periodically
// for normal event processing unless HighGUI is used within an environment that
// takes care of event processing.
// The function only works if there is at least one HighGUI window created and
// the window is active. If there are several HighGUI windows, any of them can
// be active.
//
// For further details, please see:
// https://docs.opencv.org/4.x/d7/dfc/group__highgui.html#ga6d20fbd3100ec3badc1eaa653aff99d7
func (w *Window) PollKey() int {
return int(C.Window_PollKey())
}

// MoveWindow moves window to the specified position.
//
// For further details, please see:
Expand Down
1 change: 1 addition & 0 deletions highgui_gocv.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ void Window_SetProperty(const char* winname, int flag, double value);
void Window_SetTitle(const char* winname, const char* title);
int Window_WaitKey(int);
int Window_WaitKeyEx(int);
int Window_PollKey(void);
void Window_Move(const char* winname, int x, int y);
void Window_Resize(const char* winname, int width, int height);
struct Rect Window_SelectROI(const char* winname, Mat img);
Expand Down
10 changes: 10 additions & 0 deletions highgui_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,16 @@ func TestTrackbarWithValue(t *testing.T) {
}
}

func TestPollKey(t *testing.T) {

w := NewWindow("polly")
defer w.Close()

if v := w.PollKey(); v != -1 {
t.Errorf("got %d want -1", v)
}
}

func TestWaitKeyEx(t *testing.T) {

w := NewWindow("wait")
Expand Down

0 comments on commit 41ec753

Please sign in to comment.