Skip to content

Commit 5010ae4

Browse files
committed
wkwebview: disable beeping noise on key press
Fixes #937
1 parent 79f298a commit 5010ae4

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

wkwebview/WebView/ViewController.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,4 +136,8 @@ class ViewController: NSViewController, WKNavigationDelegate, WKUIDelegate, WKSc
136136
// Implements window.close()
137137
self.view.window?.close();
138138
}
139+
140+
override func keyDown(with event: NSEvent) {
141+
// Don't call super.keyDown so that it won't play the beeping noise.
142+
}
139143
}

wkwebview/WebView/index.html

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,25 @@
55
<meta charset="utf-8">
66
<meta name="viewport" content="width=device-width, initial-scale=1">
77
<meta name="color-scheme" content="light dark">
8+
<style>
9+
textarea {
10+
width: 100%;
11+
box-sizing: border-box;
12+
min-height: 100px;
13+
}
14+
</style>
815
</head>
916
<body>
1017
<h1>It works!</h1>
18+
1119
<button onclick="testDownload()">Test file download</button>
1220
<button onclick="testCamera()">Test camera</button>
1321
<button onclick="testMicrophone()">Test microphone</button>
1422
<button onclick="window.close()">window.close()</button>
1523
<button onclick="testLocalFetchFromMain()">Test local fetch from main</button>
1624
<button onclick="testLocalFetchFromBlobWorker()">Test local fetch from blob: worker</button>
25+
<button onclick="testTextInput()">Test text input</button>
26+
1727
<script>
1828
const testDownload = async () => {
1929
const blob = new Blob([
@@ -80,6 +90,22 @@ <h1>It works!</h1>
8090
document.body.appendChild(el);
8191
});
8292
};
93+
94+
const testTextInput = () => {
95+
const textarea = document.createElement("textarea");
96+
textarea.placeholder = "Type here...";
97+
document.body.appendChild(textarea);
98+
document.addEventListener("keydown", (e) => {
99+
if (e.target !== textarea) {
100+
textarea.value = `keydown ${e.key}\n${textarea.value}`;
101+
}
102+
});
103+
document.addEventListener("keyup", (e) => {
104+
if (e.target !== textarea) {
105+
textarea.value = `keyup ${e.key}\n${textarea.value}`;
106+
}
107+
});
108+
};
83109
</script>
84110
</body>
85111
</html>

0 commit comments

Comments
 (0)