AppleScript: Can I send a keypress ignoring a pressed modifier? - macos

I've run into a rather specific problem where I would like to send a key press while having a modifier pressed without the modifier pressed.
Basically, I press Option+F4 and want to send Command+F, not Command+Option+F.
Can it be done?

Related

How to replace Discard changes with Do you want to save changes

If Esc key is pressed in
MODIFY FILE test
window, Visual FoxPro shows
Discard changes
Yes No
prompt. How can I replace this with
Do you want to save changes to test.txt
Yes No Cancel
prompt ?
A Yes/No/Cancel prompt appears if I click on the close button in the upper right corner of the close window.
Is it possible to force it to appear when I press ESC also ?
Can ON KEY LABEL esc or some custom edit windows command be used or is there some other solution ?
Yes, you could solve it with ON KEY LABEL esc someFunctionCall(). The function has then to display the dialog you desire, and you also have to write the logic whether you pressed Yes, No or Cancel. Also keep in mind, that you have to issue ON KEY LABEL esc again, so the dialog won't show up everywhere.
Another solution would be hitting CTRL+S before you press Escape. With another dialog you have to move the mouse or press another button anyways, so there is no time to safe here.

How to detect if a key was pressed by user and continue

I am new to Go, and wanted to display a text to the user and wait for the user to press any key. As soon as the user presses a key, it should proceed to the next line of code else it should stay there. How do we achieve that in Go?
Let's say the text is: "Press any key to proceed..."
and I display as:
fmt.Printf(Press any key to proceed...")
After this how do I detect whether a key was pressed in order to continue?

How does TranslateAccelerator know about CTRL or SHIFT modifier?

I'm working in a program that uses Accelerator keys for user-defined hot keys, and every thing works fine. The user can set hotkeys using SHIFT, CTRL, or ALT. I know that using ALT generates a WM_SYSKEYDOWN rather than WM_KEYDOWN, so it's pretty obvious when ALT is held down.
TranslateAccelerator only takes a window handle, the accel table handle and a single KEYDOWN message. So, my question is, if the user presses CTRL+T, how does TranslateAccelerator know the CTRL key was also pressed?
I know that the CTRL generates a separate KEYDOWN command, and I specifically filtered those out (do not pass to TranslateAccelerator) to test a theory, but TranslateAccelerator is still working.

How to dismiss an OS X modal sheet with *either* ENTER or ESC key

My application launches a modal sheet that has several buttons. One of them is the default button (key equivalent \r) and pressing the ENTER key on the keyboard dismisses the sheet, as expected. I would like to have the same effect to also be achieved if the user presses the ESC key. So either ENTER or ESC should be the key equivalent for the button. How can this be achieved?
See -[NSResponder cancelOperation:], which is automatically bound to the escape key:
This method is bound to the Escape and Command-. (period) keys. The key window first searches the view hierarchy for a view whose key equivalent is Escape or Command-., whichever was entered. If none of these views handles the key equivalent, the window sends a default action message of cancelOperation: to the first responder and from there the message travels up the responder chain.
In other words, you can handle the escape key by implementing -cancelOperation: somewhere in your app's responder chain, such as the window controller.

Press keys then type message in Textbox?

I was wondering if Visual Basic could emulate the pressing of keys.
I was thinking of a program that did this:
When I press a button (Button1) it would start a timer (Timer1), then press the V key on the keyboard and then type what was entered in a textbox (Textbox1), then press the Enter key. After doing that, repeating that action a second or two later, but saying what is in (Textbox2).
Could this be possible? If yes, please respond.
This will tell you how:
http://msdn.microsoft.com/en-us/library/ms171548(v=vs.80).aspx?cs-save-lang=1&cs-lang=vb
And use:
http://msdn.microsoft.com/en-us/library/system.windows.forms.sendkeys.send.aspx?cs-save-lang=1&cs-lang=vb
For special keys.

Resources