Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1009721
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T08:58:19+00:00 2026-05-16T08:58:19+00:00

Im trying to use SendInput to simulate keyboard presses in my app and want

  • 0

Im trying to use SendInput to simulate keyboard presses in my app and want to support both 32-bit and 64-bit.

I’ve determined that for this to work, I need to have 2 different INPUT structs as such

        [StructLayout(LayoutKind.Sequential)]
    public struct KEYBDINPUT
    {
        public ushort wVk; // Virtual Key Code
        public ushort wScan; // Scan Code
        public uint dwFlags;
        public uint time;
        public IntPtr dwExtraInfo;
    }

    [StructLayout(LayoutKind.Explicit, Size = 28)]
    public struct INPUT32
    {
        [FieldOffset(0)]
        public uint type; // eg. INPUT_KEYBOARD
        [FieldOffset(4)]
        public KEYBDINPUT ki;
    }

    [StructLayout(LayoutKind.Explicit, Size = 40)]
    public struct INPUT64
    {
        [FieldOffset(0)]
        public uint type; // eg. INPUT_KEYBOARD
        [FieldOffset(8)]
        public KEYBDINPUT ki;
    }

I wanted to know if there was a way to set the StructLayout size and FieldOffsets at runtime so I could use just one INPUT struct and determine the size and fieldoffset depending on the machine.

I have tried the code below but I would like to know if the same is possible at runtime instead of compile time.

#if _M_IX86
    [StructLayout(LayoutKind.Explicit, Size = 28)]
#else
    [StructLayout(LayoutKind.Explicit, Size = 40)]
#endif
    public struct INPUT
    {
        [FieldOffset(0)]
        public uint type; // eg. INPUT_KEYBOARD
#if _M_IX86
        [FieldOffset(4)]
#else
        [FieldOffset(8)]
#endif
        public KEYBDINPUT ki;
    }
  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T08:58:20+00:00Added an answer on May 16, 2026 at 8:58 am

    Unfortunately, no.

    Attributes are “fused” to the type at compile-time, which is why all values passed to an attribute constructor must be constants.

    And at runtime you can’t modify the attributes attached to the type. You can grab a copy and modify its values, but the actual attribute attached to the type will remain unchanged, so you can’t “trick” mscorlib code into seeing your changes instead of the original, either.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to use this sql statement. The first 2 parts work fine, I am
I'm trying use double type in openCL, but doesn't work anyway, i want use
I'm trying to use SendInput() function. I wrote this code: #include <stdio.h> #include <stdlib.h>
I am trying use a Java Uploader in a ROR app (for its ease
Trying to use this method (gist of which is use self.method_name in the FunnyHelper
Trying to use this code to connect the AD PrincipalContext context = new PrincipalContext(ContextType.Domain,
trying to use this route: from(activemq:profiles).aggregate(header(cheese)).batchSize(30).bean(ProfilesQueueService, saveContacts) Fails with: No signature of method: org.apache.camel.model.RouteType.aggregate()
I'm trying to use SendInput() on Windows but I'm building under MinGW using Eclipse
I am trying use MySql and Entity Framework, using Connector/Net 6.1 with this as
I am trying use Date Picker and on Select i want to display the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.