views:

57

answers:

2

Hi there,

So, here's a weird question: Is there a way for me to disable the menu you get when pressing the "C:\" button at the top left of the console?

I am making a game, for fun, but it would take away alot of the fun if players were able to paste words into the command-line.

I haven't found any topics about it, so I was wondering if anyone has an idea on how to get this done, or atleast a work-around.

Thanks in advance!

Edit: Would a simple reg-ex for any ^ character work? Or does the console not use ^C and ^V?

+2  A: 

I'm not sure if the console supports pasting via a keyboard combo, you can paste either via the menu or just right clicking in the console (this depends on how the console is set up though).

I'd suggest that a better solution would be to create a winforms app instead where you can control the input/output easier than in a console app.

Otherwise, one workaround might be to call Clipboard.Clear every 100ms or so to make sure that they'll never have time to copy and paste anything until you've cleared it out, but this could of course upset and/or confuse the users if they have your application running in the background and are trying to do some work in some other software.

ho1
+1  A: 

a) Use GetConsoleWindow to get window handle; use subclassing and hooks to filter mouse and keyboard events. Though this approach probably has a lot of hidden obstacles, because of Windows console implementation specifics.

b) Use timing analysis. Measure time interval between keystrokes and ignore input if this interval is unreasonably short. You may have to experiment to find the criterion that works best. Maybe it's better to measure input duration of entrie word, not inter-character intervals.

Note that pasting text to Windows console is implemented via keyboard input simulation, i.e. when you paste something to a console, the console application observes a sequence of key-down/key-up events.

atzz
This sounds like a good idea, although I'm a little bit new to the whole console application thing. So I think it's a little hard for me at the moment, but I'll try making the timing analysis later. Thank you
Nick
Don't forget that you can also paste using the following keyboard shortcut (on English Windows versions): Alt+Space, E, P.
0xA3
@0xA3 - you're right. I.e. keyboard events will have to be filtered as well as mouse events if hook approach is used. I'll modify the answer, thanks!
atzz