Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Window.PollKey() function #1198

Merged
merged 2 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading