Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. keys

keys

Scheduled Pinned Locked Moved C#
helpquestion
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    rzvme
    wrote on last edited by
    #1

    please help me. how do i simulate a key/key combination press. let's say when an event is trigerred, i want the form to act like i presse the escape key, or alt+f4!

    rzvme

    S 1 Reply Last reply
    0
    • R rzvme

      please help me. how do i simulate a key/key combination press. let's say when an event is trigerred, i want the form to act like i presse the escape key, or alt+f4!

      rzvme

      S Offline
      S Offline
      seq
      wrote on last edited by
      #2

      You can use the SendInput() function from the native win32, here is an example how to do it: http://www.cornetdesign.com/2005/04/screen-print-capture-in-c-using_08.html[^] - Pawel

      R 2 Replies Last reply
      0
      • S seq

        You can use the SendInput() function from the native win32, here is an example how to do it: http://www.cornetdesign.com/2005/04/screen-print-capture-in-c-using_08.html[^] - Pawel

        R Offline
        R Offline
        rzvme
        wrote on last edited by
        #3

        i had a look at the cide in the web site and i think i got it but i dont understand 2 things: 1) the alt key isn't in your enum VK 2) your call to the send input method (NativeWIN32.SendInput((uint)1, ref structInput, Marshal.SizeOf(structInput)); NativeWIN32.SendInput((uint)1, ref structInput, Marshal.SizeOf(structInput)); etc.) where is the alt key or print screen key in your function call? What would change in the code if , for example, i would want to pres ctrl+g instead of alt+print screen cheers!

        rzvme

        1 Reply Last reply
        0
        • S seq

          You can use the SendInput() function from the native win32, here is an example how to do it: http://www.cornetdesign.com/2005/04/screen-print-capture-in-c-using_08.html[^] - Pawel

          R Offline
          R Offline
          rzvme
          wrote on last edited by
          #4

          i added a few code lines to press enter before and escape after pressing ctrl+g .right now my code looks like this. The ctrl+g part of the code works fine, but the rest doesn't work at all. what's wrong? // to press enter structInput.ki.wVk = (ushort)NativeWIN32.VK.RETURN; intReturn = NativeWIN32.SendInput((uint)1, ref structInput, Marshal.SizeOf(structInput)); // Key up the actual key-code structInput.ki.dwFlags = NativeWIN32.KEYEVENTF_KEYUP; structInput.ki.wVk = (ushort)NativeWIN32.VK.RETURN;//vk; intReturn = NativeWIN32.SendInput((uint)1, ref structInput, Marshal.SizeOf(structInput)); //Press control Key structInput.ki.wVk = (ushort)NativeWIN32.VK.CONTROL; intReturn = NativeWIN32.SendInput((uint)1, ref structInput, Marshal.SizeOf(structInput)); // Key down the actual key-code structInput.ki.wVk = (ushort)NativeWIN32.VK.G;//vk; intReturn = NativeWIN32.SendInput((uint)1, ref structInput, Marshal.SizeOf(structInput)); // Key up the actual key-code structInput.ki.dwFlags = NativeWIN32.KEYEVENTF_KEYUP; structInput.ki.wVk = (ushort)NativeWIN32.VK.G;//vk; intReturn = NativeWIN32.SendInput((uint)1, ref structInput, Marshal.SizeOf(structInput)); //Keyup control structInput.ki.dwFlags = NativeWIN32.KEYEVENTF_KEYUP; structInput.ki.wVk = (ushort)NativeWIN32.VK.CONTROL; intReturn = NativeWIN32.SendInput((uint)1, ref structInput, Marshal.SizeOf(structInput)); // to press escape structInput.ki.wVk = (ushort)NativeWIN32.VK.ESCAPE; intReturn = NativeWIN32.SendInput((uint)1, ref structInput, Marshal.SizeOf(structInput)); // Key up the actual key-code structInput.ki.dwFlags = NativeWIN32.KEYEVENTF_KEYUP; structInput.ki.wVk = (ushort)NativeWIN32.VK.ESCAPE;//vk; intReturn = NativeWIN32.SendInput((uint)1, ref structInput, Marshal.SizeOf(structInput));

          rzvme

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups