I'm creating a utility for my mother-in-law in order to remap CTRL-C and CTRL-V commands to one signal button on her keyboard to assist with at home work. On the first press it will commit a COPY command. Next press will be a PASTE command. Since my little application won't be in focus I'll need the use of GetAsyncKeyState. Right now I'm attempting to map this all to the tilde key. How do I kill the tilde key from actually passing to the field selected and overwriting the data or appending itself to the pasted text? Could either use C# in any .NET framework or VB6 for this little applet.
I understand the answer I'm looking for could assist in creating malicious software so if anyone should feel the need to not share or delete this question then by all means do so. I'm looking for an answer to a real issue or situation. I know I could map to a none typing key like Scroll Lock or Caps Lock like some other utilities out there but both of these keys are used at this point in time and not quite an option.
You going to have to do a global keyboard hook (see VBAccelerator for some details on global hooks in VB6), and then not pass on the message once you have received CTRL-V or CTRL-C and then act on that.
Related
I created a keypad app that stays on top, but does not take the focus so that on a touch screen it will forward whatever keys you press to the active application via SendKeys.
It works perfectly with every application I have tried it with... except, of course, for the one I actually need it to work with which is a Point Of Sale application. The POS application lets the user type in item codes on the keyboard but it doesn't have a good keypad for touchscreens so that's why I'm trying to create an external one for it (since I don't have access to the POS application code).
It actually does work when you first try it, but then it's pretty sporadic. Using the keyboard directly always works, so I'm not sure why SendKeys only works sometimes with this application. I've tried implementing it several ways... sending the keys as they are pressed, sending them altogether when the user presses the enter button on the keypad, copying the keys to the clipboard and then using send keys to do a Ctl-V and then Enter.
What other options do I have to simulate a key press to another application? SendKeys doesn't seem to perfectly simulate key presses, so is there a lower level mechanism I can tap into?
I should mention that when it doesn't work, what happens is that I get a beep from the POS application as though I'd pressed an invalid key. So it's not that it isn't getting some kind of input but clearly it isn't getting the key I'm sending it the same way it would from an actual keyboard.
I found this Windows Input Simulator: https://inputsimulator.codeplex.com/
Super easy to use and way, way, way better than SendKeys. And as a bonus, in addition to letting you simulate input, it also lets you set low level keyboard/mouse hooks.
trying to write a program to flag a Key_up or Key_down event throughout the system, but I'm having a hard time with the implementation. I've seen a few posts on here that link to outdated articles on Global Hooks, but they are usually so old I cant get source code working, or theres really no explination of how it works.
I'm looking for some sort of implementation that's relitively simple (ie a library or DLL I can use, or if it's implemented by Visual Studio 2010 somewhere) as opposed to having several classes and files devoted to making a global hook.
The use of my code: I essentially want to extend the CTRL+C function to detect if CTRL is pressed, and if C and 1 are pressed (CTRL+C+1) I copy, but also store the copied text onto a notepad document.
So with that in mind it seems really extensive to design all this code only to hook onto the KeyDown/KeyUp that will be used for only 1 key
if this question has been answered recently please link me and I can close/edit this to not be redundant
OK, so almost immediately after posting this I found the sollution by re-wording my search :/ sorry to be 'that guy' everyone. BUT in the spirite of helpfulness here is a link to a SUPER quick way to get global hotkeys in your application:
http://www.dreamincode.net/forums/topic/180436-global-hotkeys/
this works for both creating new hotkeys and overriding old ones
I have built an application which listens for a global hot key (Alt + Space currently), when I press the hot key when Google Chrome is in focus it brings my app to focus but also opens Chrome's context menu (right click menu). I used the following dll for implementing the keyboard hook.
Can I prevent this from happening? If so how? This isn't a major problem but if there is a way in which you can clear all existing hot keys tied to that combination then I'd like to learn this.
EDIT
The answer that I selected as being the correct one, is the correct one but for my problem. To correctly implement this feature into a C# WinForm i used this tutorial which was very helpful: http://www.dreamincode.net/forums/topic/180436-global-hotkeys/
The FAQ section of the linked article contains your answer:
Question
I need to suppress some keystrokes after I have processed them.
Answer
Just set the e.Handled property to true in the key events you have
processed. It prevents the keystrokes being processed by other
applications.
A while ago I wrote a simple app, which surrounds selected text in any input field in any application with some unicode symbols when user presses some hotkey. Basically, app's logic is as follows:
Register global hotkey.
Hotkey fired, now set clipboard monitor and invoke clipboard copy to see if some text was selected.
If clipboard has changed and now contains text, surround said text with symbols and then invoke clipboard paste, so input field will be updated with modified text.
The problem is, I can't get copy/paste functionality from other apps in a reliable way. What I have tried to date:
If I send WM_COPY/WM_PASTE, it's more often ignored than not, depending on the application.
If I use SendInput, keybd_event or any other keyboard-messing stuff to press/unpress usual clipboard hotkeys, it will often tamper with user-pressed keys: copy/paste uses control or shift, which are also quite popular for all generic hotkeys in all apps, my app included.
If I use Journal Hook to directly inject keyboard messages into system input queue, sometimes it will work fine, and sometimes weird glitches will occur. Also, other applications may be using JournalHook for themselves, and that will mess my app badly. Not to mention that default security policies make journal hook hard to use.
I've been trying to get/set text in the input fields using Windows UI automation instead of clipboard magic, but it rarely works.
So, if you know other ways to make other applications reliably use copy/paste functionality, or can even devise entirely different approach, I'd really appreciate you telling me :)
I think your approach isn't that bad, maybe you can start with WM_DRAWCLIPBOARD so you can monitor the clipboard. A nice sample code can be found here.
Next I'd take a look at SendKeys class - Attention: Flush, Buffer, etc. Use this to send ctrl+c/v instead of a windows message! You should get a notification from your monitor if it worked.
Now I'd use the Cliboard class to maniplulate the Data and paste it back.
Oh, it seems that I could only find more or less reliable way of invoking copy-paste without SendInput or journal hook, but I have to deal with it :-) So here it is, in case someone find it useful:
Remember and reset keyboard modifiers via AttachThreadInput(yourAppThreadId, targetAppThreadId) + SetKeyboardState(keyStateWithoutKeyboardModifiers).
Set Ctrl key modifier via SetKeyboardState(keyStateWithControl) for Ctrl+C/V hotkey.
Then PostMessage to focused control handle with WM_KEYDOWN message for C or V key, whether you want it to copy or paste.
Call Thread.CurrentThread.Join(20) to let other app process messages — and that's the most retarded moment in the whole deal, since I couldn't find the sure way to know when other app will have empty message queue.
Restore remembered keyboard modifiers.
Also, every time you do SetKeyboardState, call SetForegroundWindow(focusedControlHandle) and SetFocus(focusedControlHandle) afterwards.
We are developing a hot key for one of our application.
A key combination that is
easy to remember
easy to press (especially for people
with small fingers)
certainly not ctrl-alt-del ;)
Which key combination do you suggest for a hot-key?
EDIT: Please suggest any specific character instead of generic ones.
How about Ctrl + ?
The Ctrl key is right next to the ? key. Also the question mark makes sense since none of us has any idea what the hot key is supposed to do.
It should depend on the keyboard layout, qwerty or dvorak and language configuration, of your main user. It also depends on the usage of the application when the user should trigger it. Is s/he using the mouse or the keyboard for instance.
On the topic of remembering a hotkey, using Ctrl+S for a save action or Ctrl+O for open is pretty much standard for GUI applications nowadays, so users would remember those. If the shortcut is used many times or is important in the application the user will remember it, even if it's as silly as pressing Shift 5 times in a row.
If it's not used often, it should be presented to the user in a way that it does not interrupt the work flow, as a shortcut is often displayed in a menu item for instance.
And as a final note, don't make a keyboard shortcut to remove your changes and place it next to your Save shortcut. :-)
What does the hotkey do?
Any combination with Ctrl or Alt will do, excluding the ones used by the windows UI( Ctrl+A for select-all, Ctrl+S for save, etc)
Give us more info.
Scroll Lock - it's not being used for anything else. But seriously, it will only be easy to remember if it has something to do with the application or people use it all the time.
Jay Riggs said:
How about Control + ?
The Ctrl key is right next to the ? key. [...]
That's how it is on a American/British (I don't know how these layouts are called.) keyboard. But on German/French etc keyboards ? is right next to 0. So it's not the best choice when you are planning to publish your application in several countries.
I think it's not that easy to decide, what a good hot key is as long you doesn't give us a some more details.