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. Windows API
  4. Writing own drivers?

Writing own drivers?

Scheduled Pinned Locked Moved Windows API
hardwarehelpquestion
7 Posts 3 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.
  • A Offline
    A Offline
    Anton Afanasyev
    wrote on last edited by
    #1

    I've got a need to write a custom mouse driver. Or, rather, I need to emulate a mouse (and actual hardware thing that Vista will detect as a mouse). Problem is, I've never had the need to write a driver before, and have no experience in doing so. Any pointers? Starter articles? This has to work on Vista only, but both x86 and x64 (I figure I'll need two versions, but as long as I can get it to work). Thanks a bunch in advance.


    :badger:

    L Z 3 Replies Last reply
    0
    • A Anton Afanasyev

      I've got a need to write a custom mouse driver. Or, rather, I need to emulate a mouse (and actual hardware thing that Vista will detect as a mouse). Problem is, I've never had the need to write a driver before, and have no experience in doing so. Any pointers? Starter articles? This has to work on Vista only, but both x86 and x64 (I figure I'll need two versions, but as long as I can get it to work). Thanks a bunch in advance.


      :badger:

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Can you describe a little more about what you are trying to achieve? If you simply need to insert mouse movements into the kernel input stream (emulation) then you can simply modify the \src\input\moufiltr filter driver sample which is distributed with the DDK to accept an IOCTL to insert a new mouse message into the input stream. You could even call the IOCTL from ring-3. -Randor (David Delaune)

      A 1 Reply Last reply
      0
      • L Lost User

        Can you describe a little more about what you are trying to achieve? If you simply need to insert mouse movements into the kernel input stream (emulation) then you can simply modify the \src\input\moufiltr filter driver sample which is distributed with the DDK to accept an IOCTL to insert a new mouse message into the input stream. You could even call the IOCTL from ring-3. -Randor (David Delaune)

        A Offline
        A Offline
        Anton Afanasyev
        wrote on last edited by
        #3

        Here's the problem: there is a program called Synergy. It basically allows controlling multiple computers from the same keyboard/mouse. You just slide the mouse off the edge of screen on comp1, and it moves to the screen on comp two. Very handy if you don't want to have two keyboards/mice on your desk. Now, it works fine on Windows, including Vista, until a UAC dialog appears. The UAC dialogs appear on a secure desktop, and thus synergy cannot control the mouse when on it - I have to resort to using the mouse that is plugged in to the second comp directly. Not fun :/ Now, what I want to do, is to write a mouse driver, or emulate a hardware mouse, or whatever, but basically I will modify Synergy to install this driver/emulator thing, and Windows will believe that its a hardware mouse changing the mouse position, and it will be possible to change the mouse position even when UAC dialogs popup. Well, wring the driver/emulator is a problem since I'm not even sure how to start with it. Hopefully this makes sense.


        :badger:

        L 1 Reply Last reply
        0
        • A Anton Afanasyev

          Here's the problem: there is a program called Synergy. It basically allows controlling multiple computers from the same keyboard/mouse. You just slide the mouse off the edge of screen on comp1, and it moves to the screen on comp two. Very handy if you don't want to have two keyboards/mice on your desk. Now, it works fine on Windows, including Vista, until a UAC dialog appears. The UAC dialogs appear on a secure desktop, and thus synergy cannot control the mouse when on it - I have to resort to using the mouse that is plugged in to the second comp directly. Not fun :/ Now, what I want to do, is to write a mouse driver, or emulate a hardware mouse, or whatever, but basically I will modify Synergy to install this driver/emulator thing, and Windows will believe that its a hardware mouse changing the mouse position, and it will be possible to change the mouse position even when UAC dialogs popup. Well, wring the driver/emulator is a problem since I'm not even sure how to start with it. Hopefully this makes sense.


          :badger:

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Your lucky its Sunday, I had some free time on my hands!;P Synergy: http://synergy2.sourceforge.net/[^] Assuming the above link is the correct software you are using, it is opensource. I took the liberty of downloading and inspecting the source code. It doesn't "Control the mouse" nor does it "Control the keyboard". Instead rather it is using the standard mouse_event()[^] and keybd_event()[^] functions provided by Microsoft to simulate keyboard and mouse input. You can view the code in the file located at: 'platform\CMSWindowsDesks.cpp' Here is how it begins the input attachment: void CMSWindowsDesks::deskEnter(CDesk* desk) { if (!m_isPrimary) { ReleaseCapture(); } ShowCursor(TRUE); SetWindowPos(desk->m_window, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_HIDEWINDOW); DWORD thisThread = GetWindowThreadProcessId(desk->m_window, NULL); DWORD thatThread = GetWindowThreadProcessId(desk->m_foregroundWindow, NULL); AttachThreadInput(thatThread, thisThread, TRUE); SetForegroundWindow(desk->m_foregroundWindow); AttachThreadInput(thatThread, thisThread, FALSE); EnableWindow(desk->m_window, desk->m_lowLevel ? FALSE : TRUE); desk->m_foregroundWindow = NULL; } At this point the application begins sending mouse_event() and keybd_event(). void CMSWindowsDesks::deskMouseMove(SInt32 x, SInt32 y) const { bool simple = (!m_multimon || !m_is95Family); if (!simple) {tor simple = (x >= 0 && x < GetSystemMetrics(SM_CXSCREEN) && y >= 0 && y < GetSystemMetrics(SM_CYSCREEN)); } if (simple) { SInt32 w = GetSystemMetrics(SM_CXSCREEN); SInt32 h = GetSystemMetrics(SM_CYSCREEN); mouse_event(MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE, (DWORD)((65535.0f * x) / (w - 1) + 0.5f), (DWORD)((65535.0f * y) / (h - 1) + 0.5f), 0, 0); } else { POINT pos; GetCursorPos(&pos); deskMouseRelativeMove(x - pos.x, y - pos.y); } } I dont think you need a device driver to remove the UAC behavior. I believe th

          A 1 Reply Last reply
          0
          • L Lost User

            Your lucky its Sunday, I had some free time on my hands!;P Synergy: http://synergy2.sourceforge.net/[^] Assuming the above link is the correct software you are using, it is opensource. I took the liberty of downloading and inspecting the source code. It doesn't "Control the mouse" nor does it "Control the keyboard". Instead rather it is using the standard mouse_event()[^] and keybd_event()[^] functions provided by Microsoft to simulate keyboard and mouse input. You can view the code in the file located at: 'platform\CMSWindowsDesks.cpp' Here is how it begins the input attachment: void CMSWindowsDesks::deskEnter(CDesk* desk) { if (!m_isPrimary) { ReleaseCapture(); } ShowCursor(TRUE); SetWindowPos(desk->m_window, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_HIDEWINDOW); DWORD thisThread = GetWindowThreadProcessId(desk->m_window, NULL); DWORD thatThread = GetWindowThreadProcessId(desk->m_foregroundWindow, NULL); AttachThreadInput(thatThread, thisThread, TRUE); SetForegroundWindow(desk->m_foregroundWindow); AttachThreadInput(thatThread, thisThread, FALSE); EnableWindow(desk->m_window, desk->m_lowLevel ? FALSE : TRUE); desk->m_foregroundWindow = NULL; } At this point the application begins sending mouse_event() and keybd_event(). void CMSWindowsDesks::deskMouseMove(SInt32 x, SInt32 y) const { bool simple = (!m_multimon || !m_is95Family); if (!simple) {tor simple = (x >= 0 && x < GetSystemMetrics(SM_CXSCREEN) && y >= 0 && y < GetSystemMetrics(SM_CYSCREEN)); } if (simple) { SInt32 w = GetSystemMetrics(SM_CXSCREEN); SInt32 h = GetSystemMetrics(SM_CYSCREEN); mouse_event(MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE, (DWORD)((65535.0f * x) / (w - 1) + 0.5f), (DWORD)((65535.0f * y) / (h - 1) + 0.5f), 0, 0); } else { POINT pos; GetCursorPos(&pos); deskMouseRelativeMove(x - pos.x, y - pos.y); } } I dont think you need a device driver to remove the UAC behavior. I believe th

            A Offline
            A Offline
            Anton Afanasyev
            wrote on last edited by
            #5

            :omg: Best...un-asked for....explanation...ever...:-D Anyways, thanks for the great explanation. That's exactly the way I thought the program works, but did not look a the code yet. Downloading it now. When you say that it should be possible to make Synergy UAC-aware, what exactly do you mean by it? I suppose I should just read the 3 articles, and I will, but what exactly do you mean by UAC-aware? Also, I've tried "Run as administrator" on the Synergy application, and that did not help, so I am not entirely sure that making it UAC-aware would help. I sorta want to get into driver development, but just, you know, for knowing how to and what. I'll look into the DDK and the filters you mention (and hope I can understand it :)) Also, since you sure seem to know a lot about drivers/filters, you are suggesting to write a filter, correct? How exactly do these work?


            :badger:

            1 Reply Last reply
            0
            • A Anton Afanasyev

              I've got a need to write a custom mouse driver. Or, rather, I need to emulate a mouse (and actual hardware thing that Vista will detect as a mouse). Problem is, I've never had the need to write a driver before, and have no experience in doing so. Any pointers? Starter articles? This has to work on Vista only, but both x86 and x64 (I figure I'll need two versions, but as long as I can get it to work). Thanks a bunch in advance.


              :badger:

              Z Offline
              Z Offline
              Zoltan Balazs
              wrote on last edited by
              #6

              There are some really good articles here on CP on this. Check out the series from Toby Opferman here[^]. Also check the osronline[^] site for more examples.

              Network integrated solutions A practical use of the MVC pattern

              1 Reply Last reply
              0
              • A Anton Afanasyev

                I've got a need to write a custom mouse driver. Or, rather, I need to emulate a mouse (and actual hardware thing that Vista will detect as a mouse). Problem is, I've never had the need to write a driver before, and have no experience in doing so. Any pointers? Starter articles? This has to work on Vista only, but both x86 and x64 (I figure I'll need two versions, but as long as I can get it to work). Thanks a bunch in advance.


                :badger:

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #7

                If you have about 2 years you might get somewhere. In other words, dont try it unless you really like pain, nd lots of it. Thay are a bitch to write. Seriously, about 100 times more complex than user mode code. There is SO much tat can go wrong in kernel code, you just wouldnt believe it. However, it is rather fun when you get it going.

                Truth is the subjection of reality to an individuals perception

                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