VGamepad PC
The PC app for the virtual game controller.
Loading...
Searching...
No Matches
ButtonInputBox Class Reference

A QLineEdit subclass for capturing keyboard and mouse input for key mapping. More...

#include <buttoninputbox.hpp>

Inheritance diagram for ButtonInputBox:
[legend]
Collaboration diagram for ButtonInputBox:
[legend]

Public Member Functions

 ButtonInputBox (QWidget *parent=nullptr)
 ~ButtonInputBox () override=default
KeyCodeType keyCode () const
 Returns the captured platform-native key code.
void clearKeyCode ()
 Clears the captured key code and display name.
QString displayName () const
 Returns the human-readable display name of the captured key.
void setDisplayName (const QString &displayName)
 Sets the display name without changing the key code.
void setKeyCodeAndDisplayName (KeyCodeType vk, const QString &displayName)
 Sets both the key code and display name.

Protected Member Functions

bool event (QEvent *event) override
void keyPressEvent (QKeyEvent *event) override
 Captures a key press and stores the platform-native key code.
void mousePressEvent (QMouseEvent *event) override

Private Member Functions

void updateDisplay ()

Private Attributes

KeyCodeType m_vk = 0
QString m_displayName

Detailed Description

A QLineEdit subclass for capturing keyboard and mouse input for key mapping.

This widget captures a single key press or mouse button click and stores the platform-native key code for use in input simulation.

Constructor & Destructor Documentation

◆ ButtonInputBox()

ButtonInputBox::ButtonInputBox ( QWidget * parent = nullptr)
explicit

◆ ~ButtonInputBox()

ButtonInputBox::~ButtonInputBox ( )
overridedefault

Member Function Documentation

◆ clearKeyCode()

void ButtonInputBox::clearKeyCode ( )

Clears the captured key code and display name.

◆ displayName()

QString ButtonInputBox::displayName ( ) const

Returns the human-readable display name of the captured key.

◆ event()

bool ButtonInputBox::event ( QEvent * event)
overrideprotected

◆ keyCode()

KeyCodeType ButtonInputBox::keyCode ( ) const

Returns the captured platform-native key code.

◆ keyPressEvent()

void ButtonInputBox::keyPressEvent ( QKeyEvent * event)
overrideprotected

Captures a key press and stores the platform-native key code.

Platform-Specific Behavior

Qt provides two native key identifiers, but their meaning differs by platform:

Linux (X11/XCB):
  • nativeVirtualKey() returns X11 keysyms (defined in X11/keysymdef.h)
    • For Latin letters, these match ASCII codes (e.g., XK_k = 0x006b = 107)
    • Represent the logical/semantic meaning of a key
  • nativeScanCode() returns evdev keycodes (defined in linux/input-event-codes.h)
    • Hardware-oriented codes for physical key positions (e.g., KEY_K = 37)
    • Used by Linux kernel input subsystem (evdev/uinput)

Since KeyboardInjector uses libevdev/uinput, we use nativeScanCode() on Linux.

Windows:
  • nativeVirtualKey() returns Windows virtual key codes (VK_*)
  • These are directly usable with SendInput API
Example Mappings (Linux)
Key nativeVirtualKey() nativeScanCode()
K 107 (XK_k) 37 (KEY_K)
A 97 (XK_a) 30 (KEY_A)
Enter 0xff0d (XK_Return) 28 (KEY_ENTER)
See also
https://doc.qt.io/qt-6/qkeyevent.html#nativeVirtualKey
https://wiki.archlinux.org/title/Keyboard_input

◆ mousePressEvent()

void ButtonInputBox::mousePressEvent ( QMouseEvent * event)
overrideprotected

◆ setDisplayName()

void ButtonInputBox::setDisplayName ( const QString & displayName)

Sets the display name without changing the key code.

◆ setKeyCodeAndDisplayName()

void ButtonInputBox::setKeyCodeAndDisplayName ( KeyCodeType vk,
const QString & displayName )

Sets both the key code and display name.

◆ updateDisplay()

void ButtonInputBox::updateDisplay ( )
private

Member Data Documentation

◆ m_displayName

QString ButtonInputBox::m_displayName
private

◆ m_vk

KeyCodeType ButtonInputBox::m_vk = 0
private

The documentation for this class was generated from the following files: