Skip to content

Send key implementation without locate value#4315

Merged
Maheshkale447 merged 7 commits into
masterfrom
Feature/SendKeysImplemenetation
Oct 3, 2025
Merged

Send key implementation without locate value#4315
Maheshkale447 merged 7 commits into
masterfrom
Feature/SendKeysImplemenetation

Conversation

@prashelke

@prashelke prashelke commented Sep 30, 2025

Copy link
Copy Markdown
Contributor

Thank you for your contribution.
Before submitting this PR, please make sure:

  • PR description and commit message should describe the changes done in this PR
  • Verify the PR is pointing to correct branch i.e. Release or Beta branch if the code fix is for specific release , else point it to master
  • Latest Code from master or specific release branch is merged to your branch
  • No unwanted\commented\junk code is included
  • No new warning upon build solution
  • Code Summary\Comments are added to my code which explains what my code is doing
  • Existing unit test cases are passed
  • New Unit tests are added for your development
  • Sanity Tests are successfully executed for New and Existing Functionality
  • Verify that changes are compatible with all relevant browsers and platforms.
  • After creating pull request there should not be any conflicts
  • Resolve all Codacy comments
  • Builds and checks are passed before PR is sent for review
  • Resolve code review comments
  • Update the Help Library document to match any feature changes

Summary by CodeRabbit

  • New Features

    • Send Keys now sends keystrokes to the currently focused window when no locator is provided, supporting both normal and slow send modes.
  • Bug Fixes

    • Improved handling for cases with and without a locator while preserving existing behavior for locating by window title or class name and for unsupported locator types.

@coderabbitai

coderabbitai Bot commented Sep 30, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

Added a private P/Invoke for user32.GetForegroundWindow and updated ActSendKeys.Execute: when LocateValueCalculated is empty the method logs a debug message, queries the foreground window, and sends keystrokes directly to the focused window (using SendKeysSlowly or SendKeys) then returns. Existing locate-by-title/class flows remain unchanged; no public API signature changes.

Changes

Cohort / File(s) Summary
SendKeys execution flow update
Ginger/GingerCore/Actions/ActSendKeys.cs
Added private P/Invoke GetForegroundWindow. In Execute, when LocateValueCalculated is empty, log debug, call GetForegroundWindow(), error if HWND==0, otherwise send keystrokes to the focused window using SendKeysSlowly or SendKeys and return. When LocateValueCalculated is provided, preserve existing locate-by-Title/ClassName validation and behavior.

Sequence Diagram(s)

sequenceDiagram
  actor User
  participant Act as ActSendKeys.Execute
  participant U32 as user32.GetForegroundWindow
  participant Target as Focused Window
  participant Finder as Locator (Title/Class)

  User->>Act: Execute()
  alt LocateValueCalculated provided
    Act->>Finder: Locate window (ByTitle / ByClassName)
    Finder-->>Act: Found / Not found
    Act->>Target: SendKeys / SendKeysSlowly
    Act-->>User: Done
  else LocateValueCalculated empty
    Act->>Act: Log debug "sending to focused window"
    Act->>U32: GetForegroundWindow()
    U32-->>Act: HWND (0 or non-zero)
    alt HWND == 0
      Act-->>User: Error: no focused window
    else HWND != 0
      Act->>Target: SendKeys / SendKeysSlowly
      Act-->>User: Done
    end
  end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Suggested reviewers

  • Maheshkale447

Poem

I twitch my ears at keys that fly,
A foreground pane, a quick reply.
If none’s in sight, I quietly log—
Then hop and tap on focused log.
Slow or swift, my paws convey. 🐇⌨️

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Description Check ⚠️ Warning The PR description currently only reproduces the repository’s contributor checklist template and does not include any details about what this PR actually does, why the changes were made, or how to verify them, so the required descriptive sections are missing. Please replace the checklist placeholder with a filled-out description that summarizes the changes, explains the rationale and implementation details, outlines any added or updated tests, and confirms which checklist items have been completed.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (1 passed)
Check name Status Explanation
Title Check ✅ Passed The title “Send key implementation without locate value” directly describes the primary change in this PR, which is adding support for sending keystrokes when no locate value is provided, and it is concise and focused on the main feature being introduced.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch Feature/SendKeysImplemenetation

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
Ginger/GingerCore/Actions/ActSendKeys.cs (1)

178-184: Dead code: Validation will never trigger.

After the logic fix suggested in the previous comment, the validation on line 179 becomes unreachable. Here's why:

  1. If LocateValueCalculated is empty, the code returns early (line 168 in current implementation)
  2. If LocateValueCalculated is NOT empty, execution reaches line 178
  3. Line 178 assigns titleFromUser = LocateValueCalculated
  4. Line 179 checks if (string.IsNullOrEmpty(titleFromUser)), but this can never be true since we know LocateValueCalculated is NOT empty at this point

Apply this diff to remove the dead code:

             //locate value
             String titleFromUser = LocateValueCalculated;
-            if (string.IsNullOrEmpty(titleFromUser))
-            {
-                Error = "Missing window Locate Value.";
-                return;
-
-            }
📜 Review details

Configuration used: CodeRabbit UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between dffc22c and d407371.

📒 Files selected for processing (1)
  • Ginger/GingerCore/Actions/ActSendKeys.cs (1 hunks)
🔇 Additional comments (1)
Ginger/GingerCore/Actions/ActSendKeys.cs (1)

141-142: LGTM! P/Invoke declaration is correct.

The GetForegroundWindow declaration follows standard patterns and is consistent with other P/Invoke declarations in this file.

Comment thread Ginger/GingerCore/Actions/ActSendKeys.cs
Comment thread Ginger/GingerCore/Actions/ActSendKeys.cs
coderabbitai[bot]
coderabbitai Bot previously approved these changes Sep 30, 2025
coderabbitai[bot]
coderabbitai Bot previously approved these changes Sep 30, 2025

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
Ginger/GingerCore/Actions/ActSendKeys.cs (1)

169-176: Remove unreachable validation.

The validation block at lines 169-176 contains unreachable code. The check if (string.IsNullOrEmpty(titleFromUser)) at line 171 will never be true because:

  1. If LocateValueCalculated is empty, the code returns at line 161
  2. If LocateValueCalculated is not empty, titleFromUser is assigned the same non-empty value at line 170

The empty-string check is now redundant and can be removed.

Apply this diff to remove the unreachable validation:

             //locate value
             String titleFromUser = LocateValueCalculated;
-            if (string.IsNullOrEmpty(titleFromUser))
-            {
-                Error = "Missing window Locate Value.";
-                return;
-
-            }
         }
         catch (Exception e)
📜 Review details

Configuration used: CodeRabbit UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e314d34 and 6a77b37.

📒 Files selected for processing (1)
  • Ginger/GingerCore/Actions/ActSendKeys.cs (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
Ginger/GingerCore/Actions/ActSendKeys.cs (1)
Ginger/GingerCoreCommon/ReporterLib/Reporter.cs (1)
  • Reporter (28-357)

Comment thread Ginger/GingerCore/Actions/ActSendKeys.cs
Comment thread Ginger/GingerCore/Actions/ActSendKeys.cs Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6a77b37 and 547d782.

📒 Files selected for processing (1)
  • Ginger/GingerCore/Actions/ActSendKeys.cs (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-10-01T06:43:01.042Z
Learnt from: prashelke
PR: Ginger-Automation/Ginger#4315
File: Ginger/GingerCore/Actions/ActSendKeys.cs:149-161
Timestamp: 2025-10-01T06:43:01.042Z
Learning: In ActSendKeys.cs, when LocateValueCalculated is empty, the action should send keys blindly to the current focus without validating whether a window is focused (i.e., without checking if GetForegroundWindow() returns IntPtr.Zero). This is the intended behavior to support scenarios where keys need to be sent regardless of window focus state.

Applied to files:

  • Ginger/GingerCore/Actions/ActSendKeys.cs
🧬 Code graph analysis (1)
Ginger/GingerCore/Actions/ActSendKeys.cs (1)
Ginger/GingerCoreCommon/ReporterLib/Reporter.cs (1)
  • Reporter (28-357)

Comment thread Ginger/GingerCore/Actions/ActSendKeys.cs
@Maheshkale447
Maheshkale447 disabled auto-merge October 3, 2025 08:11
@Maheshkale447
Maheshkale447 merged commit fca92bb into master Oct 3, 2025
4 checks passed
@Maheshkale447
Maheshkale447 deleted the Feature/SendKeysImplemenetation branch October 3, 2025 08:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants