Jump to content

[LE] Sending Keystrokes to Skyrim with C#


Recommended Posts

I'm not able to send any keystroke to the game from a C# program. I've tried many different methods. The game just doesn't recognize them. I've used SendKeys, Keyb_event, and Input Simulator and none of them are recognized by Skyrim but they are by other games/programs.

I've also tried, with SendKeys. to send them directly to the Skyrim Window and still got nothing.


Does anyone have an idea what I'm doing wrong?

 

I have another program, GlovePie, that sends keystrokes to Skyrim successfully, which has added to my confusion more. Voice Macro also does it just fine, so I assume it's something I'm doing wrong.

 

Here are the different C# codes I've tried (I have a mod that checks if Backslash is pressed down every second and, as i said before, GlovePie has no problem with holding down the slash key to be detected)

1.) SendKeys.SendWait("{\\}"); //Looped every 1 ms for 1 second


2.) keybd_event((byte)Key.BACKSLASH, (int)Key.DOWN, 0, 0); //Key.DOWN is pressing the key down

Wait 1s

keybd_event((byte)Key.BACKSLASH, (int)Key.UP, 0, 0); //Key.UP is releasing the key

I know the code is correct because it works for other program but maybe I need something extra for it to send to Skyrim?

Edited by zbigdogz
Link to comment
Share on other sites

What specifically are you trying to do? Why do you need an external program? With SKSE you can detect key presses just fine.

 

Event OnInit() 
    RegisterforKey(42) ;left shift 
    RegisterforKey(29) ;left control 
Endevent 

Event OnKeyDown(Int keyCode) 
    If keyCode == 42 
        Debug.Notification("Left Shift Pressed") 
    Elseif keyCode == 29 
        Debug.Notification("Left control Pressed") 
    Endif
EndEvent

https://www.creationkit.com/index.php?title=Input_Script

https://www.creationkit.com/index.php?title=OnKeyDown_-_Form

Link to comment
Share on other sites

He's looking to simulate input, and yeah I'm sure a DLL could be whipped up to enable this, or perhaps a mod I am unaware of already has done this, but in the meantime autohotkey doesnt need to be installed, and can just run with the game to do whatever you want. Takes something off SKSEs plate anyway so no reason not to other than just arbitrary preference

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...