Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // MyWindow.mm
- #import <Cocoa/Cocoa.h> // Importando o framework Cocoa
- #include "MyWindow.hpp" // Incluindo o cabeçalho da classe
- // Implementação da classe MyWindow
- MyWindow::MyWindow() {
- // Construtor vazio, aqui você pode inicializar membros, se necessário
- }
- MyWindow::~MyWindow() {
- // Destruidor, pode limpar recursos se necessário
- }
- void MyWindow::run() {
- // Criando a janela usando Cocoa
- @autoreleasepool {
- // Criar uma instância da aplicação
- NSApplication *app = [NSApplication sharedApplication];
- // Criar uma janela
- NSWindow *window = [[NSWindow alloc]
- initWithContentRect:NSMakeRect(0, 0, 800, 600)
- styleMask:(NSWindowStyleMaskTitled |
- NSWindowStyleMaskClosable |
- NSWindowStyleMaskResizable)
- backing:NSBackingStoreBuffered
- defer:NO];
- [window setTitle:@"Minha Janela"];
- [window makeKeyAndOrderFront:nil];
- // Instalação do evento de monitoramento do mouse e teclado
- [window setAcceptsMouseMovedEvents:YES]; // Aceita eventos de movimento de mouse
- // Lógica para tratar eventos (mouse e teclado)
- while (![app isRunning]) {
- NSEvent *event = [app nextEventMatchingMask:NSEventMaskAny untilDate:nil inMode:NSDefaultRunLoopMode dequeue:YES];
- [app sendEvent:event];
- [app updateWindows];
- // Checando tipo de evento (mouse ou teclado)
- if ([event type] == NSEventTypeKeyDown) {
- NSString *keyPressed = [event charactersIgnoringModifiers];
- std::cout << "Tecla pressionada: " << [keyPressed UTF8String] << std::endl;
- }
- if ([event type] == NSEventTypeMouseMoved) {
- NSPoint mouseLocation = [event locationInWindow];
- std::cout << "Mouse movido para: (" << mouseLocation.x << ", " << mouseLocation.y << ")" << std::endl;
- }
- if ([event type] == NSEventTypeLeftMouseDown) {
- NSPoint mouseDownLocation = [event locationInWindow];
- std::cout << "Clique do mouse em: (" << mouseDownLocation.x << ", " << mouseDownLocation.y << ")" << std::endl;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement