Skip to content

Webview not catching key events #75

@salmoni

Description

@salmoni

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
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions