-
February 11th, 2015, 02:27 PM
#1
Hotkeys and Hotstrings
Ok so let me first say that I am new to programming and even newer to C#. I have been using a language called AHK to create applications and scripts but I want to expand into C#. For now, I'd really like to know how to create hotkeys and hotstrings in C#. Whether it be running a particular program when F12 is pressed or sending a string when typing a few characters. Please forgive my ignorance with this language.
-
February 13th, 2015, 12:52 PM
#2
Re: Hotkeys and Hotstrings
Ok, guess this is too simple of a question for this forum.
-
February 13th, 2015, 02:53 PM
#3
Re: Hotkeys and Hotstrings
Originally Posted by bp247ind
Ok, guess this is too simple of a question for this forum.
Have you tried searching bing or google for "hotkeys in C#" ?
-
February 13th, 2015, 03:29 PM
#4
Re: Hotkeys and Hotstrings
Originally Posted by Arjay
Have you tried searching bing or google for "hotkeys in C#" ?
Of course I have. I gave two examples of what I want to do with these hotkeys because when searching for "hotkey in c#"; none of the examples are accomplishing what I am trying to do.
-
February 13th, 2015, 11:35 PM
#5
Re: Hotkeys and Hotstrings
It's hard to help if we don't know what you've tried in terms of the code you are using. With regard to F12, keep in mind that when running a C# app under visual studio, F12 will cause the program to break into debug mode.
So, I'd recommend trying to get other hotkeys working before attempting F12.
-
February 15th, 2015, 01:37 AM
#6
Re: Hotkeys and Hotstrings
Originally Posted by Arjay
It's hard to help if we don't know what you've tried in terms of the code you are using. With regard to F12, keep in mind that when running a C# app under visual studio, F12 will cause the program to break into debug mode.
So, I'd recommend trying to get other hotkeys working before attempting F12.
The F12 was just an example to illustrate the idea. I havent written any code because, like I said, I am literally just starting into this language. Any tutorials that I have been working thru deal with the Console class. I understand that it will take some time and effort to learn a new language and I am fine with that but for now I'd really like to learn this simple example to use and tweak as I am also learning through tutorials.
Just to be able to help with some work automation. Example: I have to write out the same 100 character "phrase" at work many times per day and I'd like to have my script write that out (within any other application such as notepad or web browser) by just pressing a single key or perhaps a hotstring like typing "myphrase" and the app returns the full 100 characters.
Again, this is just a simple example just so you know what I am trying to accomplish
-
February 15th, 2015, 03:25 PM
#7
Re: Hotkeys and Hotstrings
For global hotkeys in C#, search bing or google for "Gma.UserActivityMonitor" for a code project example. Also read the stackoverflow entry for how to fix an issue with the project when used on .Net 4.5.
For automating apps, search msdn for UIAutomation and/or Active Accessibility.
-
February 16th, 2015, 12:21 PM
#8
Re: Hotkeys and Hotstrings
Maybe you could do something like this in the KeyDown event?
PHP Code:
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.F12)
{
if (e.Control == true)
{
MessageBox.Show("Control + F12 pressed!");
}
else if (e.Alt == true)
{
MessageBox.Show("Alt + F12 pressed!");
}
else if (e.Shift == true)
{
MessageBox.Show("Shift + F12 pressed!");
}
else
{
MessageBox.Show("F12 pressed");
}
}
}
Hope this helps!
Matt
-
February 16th, 2015, 02:35 PM
#9
Re: Hotkeys and Hotstrings
Originally Posted by Matt Hauser
Maybe you could do something like this in the KeyDown event?
PHP Code:
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.F12)
{
if (e.Control == true)
{
MessageBox.Show("Control + F12 pressed!");
}
else if (e.Alt == true)
{
MessageBox.Show("Alt + F12 pressed!");
}
else if (e.Shift == true)
{
MessageBox.Show("Shift + F12 pressed!");
}
else
{
MessageBox.Show("F12 pressed");
}
}
}
Hope this helps!
Matt
Thank you Matt! I tend to learn better when I can visually see the code to be able to know what it's actually doing. Much Appreciated!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|