Jump to content

how do i emulate windows key?

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
15 replies to this topic

#1
toonamo

toonamo

    Newbie

  • Members
  • PipPip
  • 17 posts
I am making a program that will take commands from a remote computer using telnet and then execute keyboard presses on the machine running the program.

the main goal is to control a few video programs such as vmc and power dvd from another computer.

there are a few commands that require the windows key such as to start vmc. I have searched to find a solution but can't find anything that explains how to accomplish this only pieces.

Here is the code so far.


using System;

using System.IO;

using System.Net;

using System.Net.Sockets;

using System.Text;

using System.Diagnostics;

using System.ComponentModel;

using System.Threading;

using System.Windows.Forms;




class MyTcpListener

{

    public static void Main()

    {

        TcpListener server = null;

        try

        {

            // Get host name

            String strHostName = Dns.GetHostName();

            Console.WriteLine("Host Name: " + strHostName);


            // Find host by name

            IPHostEntry iphostentry = Dns.GetHostByName(strHostName);


            // Enumerate IP addresses

            int nIP = 0;

            

            // Set the TcpListener on port 50000.

            Int32 port = 50000;

           

            // TcpListener server = new TcpListener(port);

            server = new TcpListener(iphostentry.AddressList[nIP], port);


            // Start listening for client requests.

            server.Start();


            // Buffer for reading data

            Byte[] bytes = new Byte[256];

            String data = null;


            // Enter the listening loop.

            while (true)

            {

                Console.Write("Waiting for a connection... ");


                // Perform a blocking call to accept requests.

                // You could also user server.AcceptSocket() here.

                TcpClient client = server.AcceptTcpClient();

                Console.WriteLine("Connected!");


                data = null;


                NetworkStream stream = client.GetStream();

                string sendmsg;


            decide:


                sendmsg = "Type \"continue\" to go on or \"quit\" to stop: \r\r";

                byte[] msg = System.Text.Encoding.ASCII.GetBytes(sendmsg);

                stream.Write(msg, 0, msg.Length);

                string myInput;

                StreamReader streamReader = new StreamReader(client.GetStream());

                string line = streamReader.ReadLine();

                Console.WriteLine(line);

                switch (line)

                {

                    case "continue":

                        System.Windows.Forms.SendKeys.SendWait("A");

                        System.Windows.Forms.SendKey(70, 18, 1); 

                        goto decide;

                    case "string":

                        Console.WriteLine("auto input detected\r");

                        goto decide;

                    case "quit":

                        Console.WriteLine("Bye.");

                        break;

                    default:

                        Console.WriteLine("Your input {0} is incorrect.", data);

                        goto decide;

                }

                

                // Shutdown and end connection

                break;

            }

        }

        catch (SocketException e)

        {

            Console.WriteLine("SocketException: {0}", e);

        }

        finally

        {

            // Stop listening for new clients.

            server.Stop();

        }

    }

}


#2
acer2004

acer2004

    Newbie

  • Members
  • Pip
  • 4 posts
I'm not sure, but try to send the ascii-code of the key for example, ENTER key = 13

#3
toonamo

toonamo

    Newbie

  • Members
  • PipPip
  • 17 posts
How do i do this? i've searched for a way to send using the hex but i don't see how. I read i'm suppose to elevate my program for vista but i can't find any info on this either.

#4
Xav

Xav

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 13,118 posts
SendKeys() perhaps?
Jordan said:

Good members, like yourself, stick around and post for ages to come!
Mr. Xav | Blog | Forums

#5
toonamo

toonamo

    Newbie

  • Members
  • PipPip
  • 17 posts
are there features to the sendkeys() that are not written about. all i have been able to look up is sending letters, numbers, ctrl, alt, and shift.

it also says it must be contained within something like {abc} or (+{ABC})

thank you for giving some feedback but i still can't find a answer on how to do this. Perhaps C# isn't capable of this? I've searched for over a month and can't get an answer.

#6
Xav

Xav

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 13,118 posts
I've done some research and it looks like there is indeed no SendKeys() string that will press the Windows Key.

However, all you need to do is start programs. You can do this with Process.Start().
Jordan said:

Good members, like yourself, stick around and post for ages to come!
Mr. Xav | Blog | Forums

#7
toonamo

toonamo

    Newbie

  • Members
  • PipPip
  • 17 posts
i wish that was all i am doing.

I need to be able to send multiple key presses to control a few programs.

Basically i'm running a vista media center computer that is hooked up to my tv. from my laptop i'm controling media center by using telnet to send comands. play pause all that good stuff.

I found the api for media center that does a okay job at controling it exactly this way. but i have modified media center to be a dvd server and play bluray. The problem is when i play bluray i'm no longer in media center and now in cyberlink so keyboard shortcuts is the only thing shared across the two programs. All i wanted to do was be able to control the programs as if it was by remote.

The next option was just use an ir remote. well this doesn't work either because,
1) i can get info from media center to display on my remote laptop or on a automation controler like crestron
2) it requires two remotes.

It's funny that this is so complicated. I've seen so many things you can do with c# but i can't make a program to emulate a keyboard? How does one do it?

#8
Xav

Xav

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 13,118 posts
Could you use the Alt key to highlight a menu, then scroll to the menu and click it?
Jordan said:

Good members, like yourself, stick around and post for ages to come!
Mr. Xav | Blog | Forums

#9
toonamo

toonamo

    Newbie

  • Members
  • PipPip
  • 17 posts
unfortunately this also isn't an option. as there are no menus only keyboard shortcuts.

thank you for all the help. i may just be screwed on this one. i don't have time to take a class or even know where to take a class on this stuff.

#10
Xav

Xav

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 13,118 posts
As a last resort - automate Cyberlink with an API?
Jordan said:

Good members, like yourself, stick around and post for ages to come!
Mr. Xav | Blog | Forums

#11
toonamo

toonamo

    Newbie

  • Members
  • PipPip
  • 17 posts
havn't been able to really find anything on that....

that would also make the code complex but perhaps the only option i really have.

i suppose i'll have to do some research on that. Then maybe get someone to help me integrate the two.

#12
Xav

Xav

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 13,118 posts
I'm sorry I can't be of more help. Good luck!
Jordan said:

Good members, like yourself, stick around and post for ages to come!
Mr. Xav | Blog | Forums