Skip to content

[dotnet] Add representations for right modifier keys in Keys class #15960

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: trunk
Choose a base branch
from

Conversation

iampopovich
Copy link
Contributor

@iampopovich iampopovich commented Jun 25, 2025

User description

🔗 Related Issues

fixes #15945

💥 What does this PR do?

This pull request adds support for several new keyboard keys to the Keys class in the WebDriver library, including right-side modifier keys and macOS-specific keys. It also updates the GetDescription method to include descriptions for these new keys.

Additions to supported keys:

  • dotnet/src/webdriver/Keys.cs: Added constants for right-side modifier keys (RightShift, RightControl, RightAlt, RightCommand) and macOS-specific keys (Options, Function).

Updates to key descriptions:

🔧 Implementation Notes

💡 Additional Considerations

🔄 Types of changes

  • New feature (non-breaking change which adds functionality )

PR Type

Enhancement


Description

  • Add right-side modifier keys (RightShift, RightControl, RightAlt, RightCommand)

  • Add macOS-specific keys (Options, Function)

  • Update GetDescription method for new key descriptions


Changes walkthrough 📝

Relevant files
Enhancement
Keys.cs
Add right modifier and macOS keys                                               

dotnet/src/webdriver/Keys.cs

  • Added six new key constants for right modifier keys and macOS keys
  • Updated GetDescription method to include descriptions for new keys
  • Used Unicode character codes for key representations
  • +36/-0   

    Need help?
  • Type /help how to ... in the comments thread for any questions about Qodo Merge usage.
  • Check out the documentation for more information.
  • @selenium-ci selenium-ci added the C-dotnet .NET Bindings label Jun 25, 2025
    Copy link
    Contributor

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
    🧪 No relevant tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    Duplicate Values

    The Options key uses the same Unicode value (0xE050) as RightShift, and Function key uses the same value (0xE051) as RightControl. This creates ambiguity where different key constants map to identical character values, potentially causing confusion in key handling and lookups.

    public static readonly string Options = Convert.ToString(Convert.ToChar(0xE050, CultureInfo.InvariantCulture), CultureInfo.InvariantCulture);
    
    /// <summary>
    /// Represents the macOS Function key (same Unicode value as RightControl).
    /// </summary>
    public static readonly string Function = Convert.ToString(Convert.ToChar(0xE051, CultureInfo.InvariantCulture), CultureInfo.InvariantCulture);

    Copy link
    Contributor

    qodo-merge-pro bot commented Jun 25, 2025

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Impact
    Possible issue
    Use unique Unicode values
    Suggestion Impact:The suggestion partially impacted the commit. The Options key Unicode value was changed from 0xE050 to 0xE052, addressing the conflict issue, though not to the exact value suggested (0xE054)

    code diff:

    -    public static readonly string Options = Convert.ToString(Convert.ToChar(0xE050, CultureInfo.InvariantCulture), CultureInfo.InvariantCulture);
    +    public static readonly string Options = Convert.ToString(Convert.ToChar(0xE052, CultureInfo.InvariantCulture), CultureInfo.InvariantCulture);

    The Options and Function keys share Unicode values with RightShift and
    RightControl respectively, which could cause conflicts in key identification.
    Consider using unique Unicode values for these macOS-specific keys to avoid
    ambiguity.

    dotnet/src/webdriver/Keys.cs [375-383]

     /// <summary>
    -/// Represents the macOS Options key (same Unicode value as RightShift).
    +/// Represents the macOS Options key.
     /// </summary>
    -public static readonly string Options = Convert.ToString(Convert.ToChar(0xE050, CultureInfo.InvariantCulture), CultureInfo.InvariantCulture);
    +public static readonly string Options = Convert.ToString(Convert.ToChar(0xE054, CultureInfo.InvariantCulture), CultureInfo.InvariantCulture);
     
     /// <summary>
    -/// Represents the macOS Function key (same Unicode value as RightControl).
    +/// Represents the macOS Function key.
     /// </summary>
    -public static readonly string Function = Convert.ToString(Convert.ToChar(0xE051, CultureInfo.InvariantCulture), CultureInfo.InvariantCulture);
    +public static readonly string Function = Convert.ToString(Convert.ToChar(0xE055, CultureInfo.InvariantCulture), CultureInfo.InvariantCulture);

    [Suggestion processed]

    Suggestion importance[1-10]: 10

    __

    Why: The suggestion correctly identifies a critical issue. The PR assigns duplicate Unicode values to the Options and Function keys, which contradicts the W3C WebDriver specification that defines unique values for these keys (0xE054 for Options and 0xE055 for Function). Applying this change is essential for standards compliance and correct functionality.

    High
    • Update

    /// <summary>
    /// Represents the macOS Options key (same Unicode value as RightShift).
    /// </summary>
    public static readonly string Options = Convert.ToString(Convert.ToChar(0xE050, CultureInfo.InvariantCulture), CultureInfo.InvariantCulture);
    Copy link
    Contributor

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    On macs, Option is equivalent to Alt (left and right)

    Copy link
    Contributor Author

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    That means Java key codes should be updated as well, along with the other implementations in this feature request. OPTION here is also equal to SHIFT

    RIGHT_SHIFT('\uE050'), // aligns with ChromeDriver usage
    RIGHT_CONTROL('\uE051'),
    RIGHT_ALT('\uE052'),
    RIGHT_COMMAND('\uE053'),
    // Symbolic macOS keys not yet standardized
    OPTION('\uE050'), // TODO: verify Unicode value with WebDriver spec

    @iampopovich
    Copy link
    Contributor Author

    I noticed that there are no additional numpad keys in the code. Can I add them in this commit?
    https://w3c.github.io/webdriver/#keyboard-actions

       `NumpadPageUp` (0xE054)
       `NumpadPageDown` (0xE055)
       `NumpadEnd` (0xE056)
       `NumpadHome` (0xE057)
       `NumpadLeft` (0xE058)
       `NumpadUp` (0xE059)
       `NumpadRight` (0xE05A)
       `NumpadDown` (0xE05B)
       `NumpadInsert` (0xE05C)
       `NumpadDelete` (0xE05D)
       `NumpadEnter` (0xE007)
    

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    [🚀 Feature]: Add macOS-specific keys (OPTION, FN) to Keys enum
    3 participants