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

Webview not catching key events #75

Open
salmoni opened this issue Feb 7, 2020 · 0 comments
Open

Webview not catching key events #75

salmoni opened this issue Feb 7, 2020 · 0 comments

Comments

@salmoni
Copy link

salmoni commented Feb 7, 2020

I'm writing a web browser for tracking user behaviour in usability testing. I've managed to collect mouse events but cannot get any key events in a Webview.

Some example code: The 'FrameOnKeyDown' function should print out "Key press" to the console when a key is pressed but, alas, this does not happen.

Does the Webview capture all key events and veto any further propagation? Menu shortcuts work okay when the Webview has focus so I think I've missed something important somewhere.

What is the best way to capture key events?

package main

import (
	"fmt"
	"github.com/dontpanic92/wxGo/wx"
)


// MainFrame Objects for the mainframe
type MainFrame struct {
	wx.Frame
	Webview  	wx.WebView
}

// Key catcher
func (f *MainFrame) FrameOnKeyDown(wx.Event) {
	fmt.Println("Key press")
}

// NewFrame creates a new frame for the program
func NewFrame() *MainFrame {
	f := &MainFrame{}
	f.Frame = wx.NewFrame(wx.NullWindow, -1, "WebTrackly", wx.NewPointT(300, 100), wx.NewSizeT(800, 600), wx.DEFAULT_FRAME_STYLE|wx.WANTS_CHARS)
	f.Frame.SetClientSize(wx.NewSizeT(800, 600))
	f.Webview = wx.WebViewNew(f, wx.ID_ANY)
	f.Webview.LoadURL("http://ddg.gg")
	wx.Bind(f.Webview, wx.EVT_CHAR, f.FrameOnKeyDown, f.Webview.GetId())
	wx.Bind(f.Webview, wx.EVT_KEY_UP, f.FrameOnKeyDown, f.Webview.GetId())
	wx.Bind(f.Webview, wx.EVT_KEY_DOWN, f.FrameOnKeyDown, f.Webview.GetId())
	return f
}

//Main Function
func main() {
	wx1 := wx.NewApp("Webview test")
	f := NewFrame()
	f.Show()
	wx1.MainLoop()
	return
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant