I am using a Input system which manages input from all controllers, keyboard, etc. If you would like to check it out visit: http://mquandt.com/blog/2010/01/xna-input-manager-sample/
I have modified that input manager to have a queue system so that (in theory) would stop the event triggering to boil over when in the middle of a update.
Here is a bare bones example of my issue (This uses the XNA 4.0 framework):
http://www.mediafire.com/?9ynabpvls19u0sq
To explain my problem better if you don't want to download:
An input bind is created. After trigger the bind is deleted and a new one is added. But the same button press to delete and add the new one triggers the one that was added. This cycle continues with any number of binds. One->Three
What should happen is that on button press, old one is deleted and new one is added. Then after another button press add, delete, etc. One->Two->Three
I have figured out that if I add a breakpoint or a thread sleep of 100ms on the ActionDown of InputAction then it works correctly. I guess something is going wrong because it is going too fast but a thread sleep is not a solution.
Make DeActivate method where you can UnBind or destroy or disable your action.
Related
I am building this simple game, where a bunch of fellows that I have are supposed to seek a point indicated by a mouse click. The issue is that the Editor does not seem to notice mouse clicks at runtime. I have used the exact Input Action Asset before for detecting presses of "g" button, but it seemed to have stopped working when I played with it some more sometime later. I have since removed the asset and created w new Action Assets (one that I created manually and another that I created through the Input Action component button). Neither of them works. I have no idea what is going on and I have been looking at this for several hours now. Can someone please explain what I might have done wrong?
Different functions I used to try and get the Editor to respond to my code are below. MouseClick() is the original function that I needed to run, but did not work, onFire() is my attempt at running the default one that is given if Actions Asset is isnantiated through the component.
So it turns out that the issue was that the functions are supposed to be capitalized at the start.
Have you tried using the performed event ?
Also your Fire action needs to be a button type
I have been developing a windows application. I had built a menu bar. When I click on the menu option once, it show a checked sign. But again when I click on the same option the check sign does not goes off.
The code I had written is:
nmviewtextbox.Checked = !nmviewtextbox.Checked;
but its showing an error
I understand that you are calling this code from the CheckedChanged event and thus you are provoking an endless loop (this event is called every time nmviewtextbox.Checked is changed). In that case, delete this line (the method would continue working without any problem).
Otherwise (outside the event triggered when .Checked is changed), this code should work fine.
Bear in mind that, as suggested by Cody Gray, you can disable the check-on-click functionality (and thus allow this line of code to work without triggering any error).
Here's the scenario:
Platform: Windows
IDE: Microsoft Visual Studio 2008
Language: C#
.NET framework: 3.5
My application contains 2 buttons - "Load Data" and "Stop Loading Data" and a multi-line textbox. Upon clicking "Load Data" button some data starts getting loaded in the textbox. To prevent the user clicking on the "Load Data" button multiple times, I have disabled that button once it is clicked. When the entire data gets loaded in the textbox then the "Load Data" button gets activated again. On the other hand on clicking "Stop Loading Data" button the loading of data is stopped (if user wishes to stop it before loading the entire content).
As stated earlier, to prevent the user clicking on the "Load Data" button multiple times, I have disabled that button with the intention that user can only click on "Stop Loading Data" button or else wait for the entire data to be loaded in the textbox. I implemented this. At first glance it seemed to work well. But while testing I found that even though the "Load Data" button is disabled, if the user clicks on that button, although nothing happens at that instant but as soon as the entire data gets loaded and the button becomes enabled again, that click made during the disabled state is found to be executed. As if the program was recording the keystrokes and mouse clicks and waiting for the button to become active again. But there are no such keystrokes or mouse-clicks recording facility in my program. What is causing such an activity? How can I prevent such behavior?
Thanks.
One option would be to work with a reentrancy sentinel:
You could define an int field (initialize with 0) and update it via Interlocked.Increment on entering the method and only proceed if it is 1. At the end just do a Interlocked.Decrement.
To make it visible for the user you can disable the button at the beginning of execution and enable it when the execution is finished...
BTW: long-running tasks should be done async (via a separate thread for example)...
if you make your call a synchronous one, it will lock up the entire page until loading finishes.
Otherwise you'd be just doing the method you've already tried, i'd like to see your code for the disabled state, because something tells me you just made it appear to be disabled, and it was still a functional button
Check out this post:
http://www.codeguru.com/forum/showthread.php?t=480279
My first thought was removing the event handler and rebinding it at the end of the click event. This thread suggests using a BackgroundWorker and making it async.
I bet that you can't even move the form until data is loaded, and you also can't stop loading data. The problem is that the whole form freezes until loading is done. You must move the loading part in separate thread.
Well, another silution again:
On begin load simply hide a load button and in place of it (say) show a progress bar. On finish of loading or on stop loading click make load button visible again. In this case you avoid "chain clicks" management you complains about.
Or manage one button. First it is load, on click, instead, becomes stop load. Solution like this you would find often in mobile environment, considering the limited screen space. But I think it can be applied to desktop with great sucess too. Why not?
simply put I want my program which runs in the background to check whether the print screen button has been pressed (which mostly triggers a function within another program to generate a screenshot of the current window. eg a game screen).
I have seen lots of possible answers, but most seem overkill for just detecting the print screen button.
I want to have a program in the background check so that it can move the screenshot that has just been made/saved to a certain location. after the button had been pressed.
I hope this question is clear, if not I'll try to explain more clearly.
ps
On a side note, would it be better to try and detect the printscreen button or to simply check the specified folder every 1 or 5 minutes whether a new image has been put in that folder and then move it if true.
EDIT
I decided to use the FileSystemWatch, however it seems to be to fast if i use the on create event as sometimes the file is still being made and it can't move the file yet.
Would the best action be to use a timer to delay ?
You could just watch the folder location for updates using a FileSystemWatcher. There are many examples around the place.
Global keyboard capture in C# application
You should be able to use a global key hook to handle the print screen key press.
this is my first post. I have a huge problem which make me headaches. I have an app uses WinForms, a TTS (Text-To-Speech) voice and custom-buttons with states.
In my 1st form -main- when I click a button, the app opens a 2nd form above the 1st. Ok.
When I close the 2nd form trough a button, I tell the TTS say something and the form closed itself, viewing again the 1st form. Ok.
The problem starts when I click two times in the button on the 2nd form: the TTS says something, the button closes and the 'second click' is still in the click buffer (or somewhere) and it makes click in the 1st form (which appears 4 seconds later when I hit the button for the first time).
I am using the voice in a Sync mode; if I use the voice in an Async mode, the application ends wit h a nice exception.
If I click three or four times in the 2nd form, the other clicks still remains in buffer and clicks in the 1st form all the times.
I tried to (1) delete the DoubleClick event, (2) delete the event associated to the button and (3) hide the button which is clicked automatically when I return from the 2nd form, (4) hide the 1st form before create the 2nd and restore when it finishes.
Suggestions?
Thanks!
PD: I'm sorry by my English :S
PD2: I've uploaded a very simple example of what happens.
EDIT 2
Having looked at the code I understand the issue you're having now. The reason button clicks are being stacked up is when you call Speak within TTS the application locks up while it waits for the function to finish. Any presses in that time are stacked up until the application is free again to process them, you then close the form instanly before the messages are handled and these are then dealt with in the first form.
I've come up with a few solutions which could work for you:
Use only the SpeakAsync command within your TTS class and introduce a Waiting system where you wait for the speech to finish before doing anything. This will free the application and won't cause the mouse click events to stack up.
After you trigger a Speak command you could access the Windows message list and clear all the mouse click events that occurred before the process finished. Unfortunately, I'm not sure how you'd implement this as I've not done this before. I think you need to overwrite the WndProc function but again I'm not sure. This might be also be a bit dangerous as you may end up clearing a perfectly valid or important system message by mistake. Sorry can't provide any more help on that one.
Implement a background worker in your second form which will process the Speak commands seperately on a background thread. This again will free the application so the mouse click events won't stack up. I've modified your sample project and zipped it up for you to take a look. If you want I can explain further but essentially it does the following:
Form 2 loads and creates a background worker.
Worker_DoWork and Worker_WorkComplete delegates are created and set in the background worker. These functions are called when the worker is started and after the worker has finished.
Form 2 triggers the background worker to start. The background worker then sits in an infinite loop waiting for commands to process.
When the "Hello" button is pressed this sets a SayHello boolean to true, the worker spots this, carrys out the appropriate speak function and then resets the boolean ready for the next press.
When the "Close" button is pressed a CancelASync request is called in the background worker.
CancelASync interupts the BackgroundWorker's main loop (CancellationPending becomes true). The appropriate speak command is sent and the cancel property of the DoWorkEventArgs is set to true before breaking out of the BackgroundWorker's main loop.
Breaking out of the main loop causes Worker_WorkComplete to be called where the form is then closed.
I hope you can follow the example (linked below) and I've explained it well enough here. I prefer this solution as its quite extendable, you can add more conditions within the main worker thread for example.
Like I said, if you have any questions please ask and I'll try help as much as possible.
Hope this helps.
Example Link: http://www.mediafire.com/?2mf1yahto50ljs6
Use a boolean flag to track whether the form is in a state that accepts the click.
IE - when you open the 2nd form, 'boolean canPlaySound = true;' When the button click event fires, only play the sound if canPlaySound is true (and set it to false before playing the sound).
The next click will be ignored because canPlaySound = false. You won't play the sound.