Thread: Talking w/ hardware

  1. #1
    Registered User
    Join Date
    Jan 2005
    Posts
    12

    Talking w/ hardware

    I was wondering how to send/receive signals to and fo hardware with c++? I'm not asking for a complete description, just a phrase that I can search google with to get a tutorial on this subject. The subject being, for instance, how to code for one program to tell another program that the 'P' button on the keyboard has been pushed or that the mouse was moved up y and over x, when the keyboad 'P' or mouse was never physically touched. Thanks for your advice in advance.

  2. #2
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    There is no mechanism in C++ that offers port input and output. The usual way is inline assembly.
    It is possible to write interrupt handlers partially in C/C++. But installing them is still likely to require some assembly.

    However, modern OSs (Linux, Windows) will disallow this direct communication with the hardware.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  3. #3
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >I was wondering how to send/receive signals to and fo hardware with c++?
    Code:
    cout<<"Hello, world!"<<endl;
    My best code is written with the delete key.

  4. #4
    Registered User
    Join Date
    Jan 2005
    Posts
    12
    How do bots work then if you can't directly send to the hardware?

  5. #5
    ---
    Join Date
    May 2004
    Posts
    1,379
    API calls

  6. #6
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    With Windows, you can get a handle to a port with the CreateFile() API function. Once you have a handle, you can use the handle based I/O routines.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  7. #7
    Hardware Engineer
    Join Date
    Sep 2001
    Posts
    1,398

    Lightbulb Let's pretend you're running windows... PostMessage()

    Ah, I think I found it: PostMessage() sends a "message" to the Window.

    How Windows Programs Work: Each windows application runs a loop which checks for messages from the operating system. For example, when you press the left mouse-button down, the operating system sends a WM_LBUTTONDOWN message to the message queue.

    Note that sumulating a key-press or mouse-click does not require accessing hardware (on a Windows system). It's done through the OS.

    Windows programming is not that easy. Here's a Windows tutorial. You'll need to at least know how to get a handle to the target window, and you'll need to look-up the WM_ messages.

    [EDIT] -
    If you want an easy (Not C/C++) way of automating clicks & keystrokes, check-out WinBatch. I've used WinBatch to automate stuff that had to be run nightly.
    Last edited by DougDbug; 01-10-2005 at 04:49 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 21
    Last Post: 06-24-2009, 09:49 AM
  2. Hardware interrupts
    By Sentral in forum Tech Board
    Replies: 5
    Last Post: 02-23-2009, 06:46 PM
  3. X-10 Hardware
    By jmd15 in forum Tech Board
    Replies: 1
    Last Post: 09-29-2005, 07:34 PM
  4. How does hardware interpret data?
    By Silvercord in forum Tech Board
    Replies: 3
    Last Post: 01-29-2003, 01:46 PM
  5. Linux Hardware Handbook
    By Nutshell in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 04-02-2002, 06:06 AM