Author |
Message |
DanielG
|
Posted: Tue Aug 05, 2008 1:00 am Post subject: how do I make the computer think a button is pressed? |
|
|
can someone tell me how to make the computer think a button or the mouse is pressed. So for example, have it so that while the programming is running, if you press on the button 'n' it might think you pressed 'r' at the time. Can someone tell me how to do this in preferably C++ or Turing. Though if it's possible and easy to do it with another language then thats fine.
Thanks. |
|
|
|
|
|
Sponsor Sponsor
|
|
|
DemonWasp
|
Posted: Tue Aug 05, 2008 8:34 am Post subject: RE:how do I make the computer think a button is pressed? |
|
|
Erm...what exactly were you trying to do? Is faking keystrokes really what you wanted to do?
If you're just doing this for your own use, you may want to look into xmodmap (assuming you're running Linux). |
|
|
|
|
|
apomb
|
Posted: Tue Aug 05, 2008 8:38 am Post subject: RE:how do I make the computer think a button is pressed? |
|
|
so, you want to remap your keyboard? |
|
|
|
|
|
Insectoid
|
Posted: Tue Aug 05, 2008 8:54 am Post subject: RE:how do I make the computer think a button is pressed? |
|
|
This doesn't seem like a good plan to me... |
|
|
|
|
|
DanielG
|
Posted: Tue Aug 05, 2008 9:29 pm Post subject: RE:how do I make the computer think a button is pressed? |
|
|
I am using windows. I want to write a program that, while running, if I press on 'r' then it would send to the computer the same signal as if some other keys in a specific order were pressed. |
|
|
|
|
|
rdrake
|
Posted: Tue Aug 05, 2008 10:21 pm Post subject: RE:how do I make the computer think a button is pressed? |
|
|
I know for a fact that you can hook into the Windows API in order to wait for key presses. You could wait for 'r' to be pressed, then do whatever you want afterwards. Check out this site for a VB(.NET) example.
As for actually sending key events, I'm not sure. There's probably somewhere in the API to send key presses as well. |
|
|
|
|
|
Euphoracle
|
Posted: Wed Aug 06, 2008 9:14 am Post subject: RE:how do I make the computer think a button is pressed? |
|
|
Using .Net2 and up, you can use SendKeys to emulate keystrokes at the most basic of levels, but if you want to send them at low level so that DirectInput, etc applications will intercept them, you'll have to use the win32 api and keyboard_event or whatever it's called. Remember, some applications take input before windows to ensure the snappiest controls, sometimes you cannot emulate keystrokes to these applications without using hardware loopback or software keyboard drivers. I can't remember the example in which this was the case. I thought windows still processed input before some DirectInput applications, but I've been told this isn't true. |
|
|
|
|
|
Zeroth
|
Posted: Wed Aug 06, 2008 1:13 pm Post subject: Re: how do I make the computer think a button is pressed? |
|
|
Sounds like you want an alias for a specific command? Is this a command line alias, or a macro of mouse clicks/etc that you want executed? |
|
|
|
|
|
Sponsor Sponsor
|
|
|
DanielG
|
Posted: Thu Aug 07, 2008 12:55 am Post subject: RE:how do I make the computer think a button is pressed? |
|
|
I know how to read key presses in my programs, what I don't know is how to make other programs believe a key is pressed when it is not. |
|
|
|
|
|
DemonWasp
|
Posted: Thu Aug 07, 2008 7:58 am Post subject: RE:how do I make the computer think a button is pressed? |
|
|
Then you want what Euphoracle was talking about. I still can't see much of a reason to do this, though, aside from perhaps drivers for keyboards with bonus keys. |
|
|
|
|
|
Zeroth
|
Posted: Thu Aug 07, 2008 8:14 am Post subject: Re: how do I make the computer think a button is pressed? |
|
|
Seriously answer my question... but take a look at this: http://www.autoitscript.com/autoit3/ |
|
|
|
|
|
Euphoracle
|
Posted: Thu Aug 07, 2008 9:59 am Post subject: RE:how do I make the computer think a button is pressed? |
|
|
Autoit is a high level wrapper and external scripting parser for the SendMessage and/or SendInput win32 api call. To answer your question, since you're being so snatty now,
USE SENDMESSAGE OR SENDINPUT.
MSDN for how to use it. G'day. |
|
|
|
|
|
Zeroth
|
Posted: Thu Aug 07, 2008 11:07 am Post subject: Re: how do I make the computer think a button is pressed? |
|
|
Euphoracle, I was talking to the OP here. I'm trying to figure out precisely what he wants, like a set of commands executed, or what. I wasn't being snatty, and neither was the OP. I can see how you got us confused though. (And just so you remember, the OP is DanielG, not me. I was just suggesting a solution for him. sheesh. ) |
|
|
|
|
|
unoho
|
Posted: Thu Aug 07, 2008 12:10 pm Post subject: RE:how do I make the computer think a button is pressed? |
|
|
umm... im really noob at programming, but can't u just make it like this ?? plz forgive me if im mistaken.
this is how i would do it in turing:
make a procedure tht u want to occur whn u press r
thn a if statement to say if "r" is pressed, then r procedure will happen
elsif y is pressed, the same r procedure will happen
blah blah blah.. something like tht?? |
|
|
|
|
|
btiffin
|
Posted: Thu Aug 07, 2008 12:39 pm Post subject: RE:how do I make the computer think a button is pressed? |
|
|
unoho; I don't usually gripe about spellingz.
Ken Thompson; in a footnote in The Unix Programming Environment by Kernigan and Pike, when asked what he might have done differently if reassigned Unix.
"I'd spell creat with an e".
Cheers |
|
|
|
|
|
|