Crafter.CppDOM/examples/EnhancedEventHandling/main.cpp
2025-11-10 20:25:50 +01:00

21 lines
No EOL
785 B
C++

import Crafter.CppDOM;
using namespace Crafter;
import std;
HtmlElement* body = new HtmlElement("body", "<div id='container'>"
"<h1>Enhanced Event Handling Demo</h1>"
"<input type='text' id='keyInput' placeholder='Press keys here'>"
"<div id='output'></div>"
"</div>");
HtmlElement* keyInput = new HtmlElement("keyInput");
HtmlElement* output = new HtmlElement("output");
int main(){
keyInput->AddKeyDownListener([&](KeyboardEvent event) {
std::string keyInfo = std::format("<p>Key pressed: {}</p>", event.key);
if (event.ctrlKey) keyInfo += "<p>Ctrl key pressed</p>";
if (event.shiftKey) keyInfo += "<p>Shift key pressed</p>";
if (event.altKey) keyInfo += "<p>Alt key pressed</p>";
output->SetInnerHTML(keyInfo);
});
}