How to perform keyboard shortcut in VB - vb.net

I would like to know if it's possible, and if so how, to use VB.NET to automate the input of a keyboard shortcut.
In the application i am developing, it receives email as a outlook addin and runs various checks and if those checks are positive it inserts information about the message into the database.
But i want to be able to tell it that when the subject = "Keyword" to perform Ctrl+Alt+↑ for, essentially a prank.
However I can't find anything on this anywhere, all i find is "Custom Short-cuts In VB.NET" and stuff about the KeyDown, KeyUp and KeyPress events.
Thanks

I think the easiest way to do such a thing would be to use the SendKeys method. Untested I think Ctrl+Alt+↑ would look like:
SendKeys.Send("+(^{UP})")
MSDN SendKeys

Related

How to check if VBA application is in focus when GetAsyncKeyState is pressed

I have a long running application written in VBA. Because it runs for a long time I call a sub from the main loop every iteration to check if the user has pressed the escape key. The sub is listed below. The code works great except that it is always listening, even when the VBA application does not have the focus. What's the best way to approach this? Is there an alternative to GetAsyncKeyState which only listens when the correct application is in focus, or are there system calls I can use to check that the correct window is in focus.
Private Sub checkForUserEscKeyAbort()
'Listen for escape key and exit gracefully if user aborts.
Dim abortResult As VbMsgBoxResult
If GetAsyncKeyState(vbKeyEscape) Then
abortResult = MsgBox("Escape key pressed, do you want to abort?", vbYesNo)
If abortResult = vbYes Then Call teardownSLICER
End If
End Sub
The problem is the way GetAsyncKeyState operates. It does more than just check it the key is currently down, it also checks if the key was pressed since the last time GetAsyncKeyState was called. Thus, your problem of "always listening".
You could use GetKeyState, but frankly, I'm not a fan of that option either. Your code must be well crafted to avoid a polling window that is so small that you literally have to hold the key down to ensure it isn't missed.
A viable alternative is key masking where you use a combination of keys such as Shift-Escape. There is a decent introduction to this (and many other subjects) on Chip Pearson's site. However, this is still not my preferred method.
My preference has already mentioned in the comments. Your application may best be improved with a user form. It also gives you the ability to get information in front of the user. Perhaps they wouldn't try quitting the application if a progress bar on the user form indicated 95% completion. Maybe you can add a pause button that free's some resources for a prescient need and then resumes when the user is ready. That little extra functionality on its own is enough to win me over but there is an even better reason for using a User Form - it does exactly what you asked!
User forms, and many user form controls, have Keydown, Keyup, and Keypress events that only trigger when the form (or control) have focus. This is precisely what you wanted.

sendkeys does not seem to be working in vba

I am trying to use an excel add in in VBA. Unfortunately recording the macro doesn't seem to work and hence the reason I want to try use the keyboard shortcuts. The shortcut I am after is ALT X 2 V. I have tried using SendKeys.send ("%{x}{2}{v}")
but every time I try to use it, the code write the values "2v" to my vba screen. I am not sure I have fully understood how to use this method as I want the actions to be actioned in excel so that I can access this add in.
I have been through the forums but can't seem to get an answer, which includes putting a wait command between each keystroke. Could really do with some help.
Try SendKeys "%x2v"
That said, using sendkeys is almost always a Bad Idea. I understand that you're trying to call some function from an addin, but if you're able to access that code at all, I would do so, and call whatever you're trying to run directly. At some point, SendKeys will mess something up.

VBA Macro changing macro

Is it possible to create a macro in MS Office (in this case Word) that will change other macro code? I was trying to find information but no results.
I have a doc which works as a template. Content of template is changed and then saved to another file. However it is important to have current date in it. It cannot be self-updated. Those docs go to folder of people and it is important to know when they get the document, so it must be simply data (or something that does not update).
I was thinking about an on-start event macro that would input current date and on exit it would ask "Do you want self-update functionality" Yes / No
If Yes, delete that event. However I have no idea if it is possible. If it is I still don't know how to search for it.
No this is not possible. In VBA, unlike some lower level languages when you define an event you can not disable it, even using other VBA code.
In C# or VB.NET, Java or C++ you can disable an event by un-wiring it from the handler, but this is not possible in VBA.
Maybe if you be more clear on what you need I can give you a better answer.

Capital Only Edit Control

Having a bit of a problem doing this and not sure of it can be done. I have an edit control that a user types into, I would like for the input to be all in capital letters. I tried having a custom action on the edit control to get the property, convert to capital letters and set the property again each time a letter is set but it does not work. I guessed it wouldn't but no harm in trying..:)
Has anyone else solved this? I would like to do it without having a button to press if possible. The dialog in question is a twin dialog if that helps at all.
Thanks for your help
It's not possible using the native built-in Windows Installer UI. The underlying MaskedEdit Control is primitive. There are no events to tie into to validate and modify as the characters are entered. You can only ToUpper() the property when the user clicks Back or Next.
The alternative would be to go with an external UI handler which is a lot of learning and work.

WatiN handler for vbscript Input Box

Do anyone have a solution for handling a vbscript inputbox with watin, and to be clear this is not the same a javascripts prompt or vbscript msgbox or etc....
I have and used handlers for those but cannot find a way to handle the input box and i do not have the pull to get the developers to change the code to use prompt and javascript like they have in some many other places in our old vb6 systems.
You should create a custom dialog handler that can handle the window. The trick to doing that is to get spy++ and match the right window style. Another method might be to call the document.eval method and close it using javascript.