I am trying to design a little program that takes input from two PS2 controllers from a USB converter. I would like to take input from all the buttons including pressing the joysticks in (L3, R3), and the joysticks position, and whether the analog is on. I would also like to send feedback back to the controllers and run the two vibration motors and possibly control the LED for analog.
What I'm looking for is a C# source code file that can do it all or an already compiled all-in-one DLL or even a beginners tutorial.
You will likely need to develop a .NET library of your own to interface with a PlayStation controller, and this could get pretty involved. This article can help get you started. Good luck!
Check out this project:
http://www.codeproject.com/Articles/16704/Interfacing-with-a-Joystick-using-C
Also read: http://213.55.83.214:8181/Computer%20Science/Programming/01428.pdf
Not the entire book but parts that are relevant for what you need.
Related
I'm working on a small tool for a DirectX game and I want to prevent the user from pressing a certain key (F12 in this case) for a certain period.
I could find many options for simulating keypresses but what are the options when it comes to nulling out a keystroke before the game reads it?
The language doesn't really matter, although I would prefer a C# or C++ solution, or just a nudge in the right direction :)
Thanks in advance!
The good news is, I've done this before so I can say that it is possible and it does work.
The bad news is that it's not simple. It requires a lot of complicated code, and will likely take a long time to implement, but I'll explain how you can do it.
Applications like DirectX games usually register for raw input.
Since you want to stop a keyboard event from reaching the application, you need a way to insert your code between the raw input and the game so you can check the raw input and decide whether to allow it to be passed to the game:
So you want to change the flow from:
Raw Input --> Game
to
Raw Input --> Your Code --> Game
Without having access to the source code of the game, you have to find a way to insert your code.
When there is keyboard input available, the game will call the WinAPI function GetRawInputData, which will tell it about the keyboard event. Ideally, what we want is when the game calls this function, it actually calls our code instead of the WinAPI function. Then we can decide what to tell the game about the keyboard event, we could tell it anything we want (e.g. ignore F12). Sounds great right? Here's where it gets interesting...
We can take advantage of how windows loads executables into memory. Typically, a program uses (or 'imports') calls to functions in other DLLs (such as GetRawInputData, in User32.dll). When the program gets loaded into memory, Windows will fill in a table (the Import Address Table (IAT)) with pointers to the executable code in the appropriate DLLs. This means that when the program calls the function, it gets directed to the executable code in User32.dll in memory to run it.
Wouldn't it be great if we could write/patch the address of one of our functions into that table, so that when the game calls GetRawInputData, it actually gets directed to our function for us to process? Well we can! It's called Import Address Table Patching.
There's a pretty good article on it here with some working code in C++. You should first read it to understand in more detail how it works, then you can modify it to support your needs. It will work, but I know it's probably more work (much more work) than you would have been hoping for, but essentially you're hacking the application which is never easy to do.
It's worth doing, even just to gain a better understanding of Windows behind the scenes.
Good luck!
EDIT
As Simon said, Windows Hooks is a much simpler way to do it if the game isn't using raw input. DirectX Games tend to be a special case that don't really work too well with standard Hooks as they use special methods to get the input from the user. By all means give it a go though, it will be a lot easier if it works.
I want to create a program that can log gathering in a RPG for me, the problem is that I dont know where to start. I know c++ and some c#, but I haven't got a clue on how to scan the screen.
What I've looked at:
Screen scraping (most info is on scraping HTML pages)
OCR (Most info
is on OCR on a image file, not an active window)
Spy++ (I haven't got
a clue)
I can do it with any language, but I'd prefer c++ or c# since that what I'm most experienced in
What is the best way to do it? anyone got some helpful links/tips?
example of something I'd like to know (amongst other things):
Would it be wise to make a screenshot like once every seccond and then analyze that image?
Should I learn and use windows API for this?
before you bash me:
Yes, I know that this will be a big project, nothing I expect to complete easily
Yes, I understand that I will have to learn more about programming to do this (that's part of the goal)
Yes, I understand that it might be more than I can handle at my current level of skill, but I'd like to figure that out by trying :)
Please help me, I really dont have a clue about where to start
If you are serious about creating this program I would suggest you forget about scanning the screen, image analysis gets very complicated very quickly.
Instead look into memory reading, the information shown in the game can also be read as a straight up value from the games working memory.
There are probably resources out there for your game already, google it.
World of Warcraft
Diablo 3
etc
I'm an electronics engineer used to coding in embedded C and assembly, but I decided to start learning higher-level stuff like C#, .NET, etc., so I can start making software as a hobby. I have a great idea for one of my first projects, but after searching several forums for days on end, I'm left not really knowing what would be the easiest path forward.
The functionality that I'm looking to create is pretty similar to the idea of a photo slideshow, but applied to videos instead. The program would open a playlist or a folder full of videos and then play the videos in a random order, starting from a random starting position, and with a fixed duration (let's say 10 seconds as an example). You would end up being able to watch a sort of "video montage" that consisted of small clips from random parts of the videos in the playlist, shown in a random order, ad infinitum until the program is closed.
There are a number of ways I could tackle the problem:
Develop a standalone video player with the fixed functionality of showing "video slideshows." DirectX has the Microsoft.DirectX.AudioVideoPlayback API that
could be a good starting point. I found an example here: http://www.dreamincode.net/forums/topic/111181-adding-video-to-an-application/
Modify an open source project to add the desired functionality. I've seen a few cool projects that could get me started, like this simple C# Movie Player: http://www.codeproject.com/Articles/18552/C-Movie-Player
Use a scripting interface to implement this functionality on an existing media player, like VLC or Winamp. You could also control VLC via C#, like the example here: Controlling VLC via c#
I realize that the obvious answer for most people would be to "use whatever you're most comfortable with," but since I'm a pure beginner, I don't really have any allegiances to a particular language or development environment. So, I was just curious if anybody had an idea of what might be the least painful option for a beginner.
I also apologize that this is not a very specific programming question. I'm sort of just testing the waters to get my footing. Hopefully, once I get started on the project, I'll be able to come back and post more intelligent and relevant questions!
While your background would lend you toward C#, I recommend investigating something like this and using WPF for the media player. You can then control the media player using a background worker in order to stop the video or queue up the next one. Some other .NET concepts that will be of use to you are FileInfo and DirectoryInfo objects, to provide you with the necessary information about the files. I'm not sure if you've had experience with generic data structures in .NET, but the System.Collections.Generic namespace would be a good place to start to get a feel for data structure you want to keep your playlist in. WPF will also be able to help you with transitions between video clips.
Admittedly WPF is easier with an understanding of the MVVM or MVC design patterns, but I think you'll be able to get something working without having to delve too far into that right up front.
I need to listen for keyboard events from a specific keyboard device & know which key is pressed in a (C#) WPF application. Ideally, this shouldn't be window dependant and work so long as the application has focus.
unfortunately I can't think of / find any way to do this.
any ideas?
D.R
Edit: I've been looking into the OpenTK.Input library, which has a nice interface for keys... Does anybody know how to get a KeyboardDevice without creating a GameWindow
Info: Just by the way, this is for a barcode scanner which emulates a keyboard... who's bright idea was that, eh?
I'm actually working on a project that does exactly that. Check out Kaptivate. It installs a global keyboard hook, and ties together (using magic) the raw input api, and then invokes a callback function so that YOU can decide (1) is this the device I'm after?, and (2) should I allow other apps to see it, or just keep the keystroke for myself. Right now it's only C++ but one of the goals is eventually to have C# wrappers.
For keyboards, each generated event tells you the vkey, scan code, and source device.
Have a look at the below 2 articles.
Using global keyboard hook (WH_KEYBOARD_LL) in WPF / C#
https://gist.github.com/471698
both should be exactly what you want...
Managed to find this tutorial on msdn. along with a Sample Scanner object which comes with the POS.Net SDK
I haven't really had the time to pick apart how it works yet to give a proper overview, but it seems I should be able to write a custom service object abstraction for any "keyboard wedge" HID device.
I am about to write a front end app, which will be used as a media center app. It will plug directly into a high definition TV. Essentially transforming my laptop into a media player. While this concept is not new, I want custom functionality, so this is why I am not reusing existing products.
I'm a C# developer, so the app should ideally be written in C#. And there is 1 other consideration, I need to accept input via the MCE Remote.
I was considering using Silverlight for this. Would you recommend this? Or any other recommendations for frameworks before I begin planning around this.
Thanks in advance.
This is the type of stuff that the Windows Presentation Foundation was meant for. You'll get a lot more access to the hardware than Silverlight would provide (I.E. that MCE remote you mentioned). You mark up your UI with vector graphics/XAML, and then perform the logic with C#.
EDIT: WPF also has support out of the box for animations which can make your UI a lot more interactive.
EDIT 2: Scott Hanselman has written a really cool application called BabySmash and posted the source online. It basically intercepts keyboard input and shows shapes and sounds on the computer. It's a good "child-proofing" method for your PC. The code could provide you with some insight into WPF and how to do the animations and interactivity that you're looking for.
Is this a desktop app? If so I would use WPF. Silverlight is a subset of WPF, so using WPF you could potentially do more.
Silverlight or WPF, if you want some extra power. Both have a similar programming model (with XAML and code-behind) so you might be able to start with Silverlight and move up to WPF if you need.
The VLC api might be useful for playing your media, someone has created a C# wrapper for it:
http://wiki.videolan.org/.Net_Interface_to_VLC
WPF is certainly the way to go, and for playing media check out the excellent WPF MediaKit: http://wpfmediakit.codeplex.com/ I've used it successfully in many projects.