Reading Ctrl + until found a non-digit from keyboard - c#

It's possible once Ctrl was pressed, get all keys pressed before until a non-digit was found? valid inputs:
Ctrl + 1 // do something with 1
Ctrl + 2 // do something with 2
//..
Ctrl + 30 // do something with 30
it's a will works as the FN keys, but instead of it, I wan to use Ctrl and extend the range from 0-9 to 0-50. I hope this is clean. Thanks in advance.
Note: I tagged C# and C languages because either of these languages is valid for my use case.

A low level keyboard hook should be able to do this. Use SetWindowsHookEx with WH_KEYBOARD_LL. You can find some C# implementations on the Internet.
I generally discourage the use of keyboard hooks due to their global side effects, but I can't think of anything else that fulfills your requirements.

Related

ReSharper reorder String.Format() arguments

I often find myself writing something daft like:
String.Format("{1}: {0}", reason, message);
or something similar but with far more string placeholders.
Is there an automated refactoring in ReSharper to change the order of the placeholders and the arguments? I have a tendency to mess up the mapping if I try to change the order by hand.
Obviously, the example above is trivial. What I am doing in reality is often writing something like:
String.Format("{0}.{2} = {1}.{3} AND {0}.{4} = {1}.{5} AND {6}.{7} = {1}.{8}",
table1Alias, table2Alias, col1A, col2A, col1B, col2B, table3Alias, col3C, col2C);
and thinking to myself that it would be great if I could move table3Alias up to the front next to the other aliases.
(ReSharper 7.1.3)
For C# 6+ (ReSharper 10+ / 2016+):
Place your cursor at string.Format
Press Alt + Enter
Select Use string interpolation
Press Alt + Enter again
Select Convert to string.Format
No, there is no such functionality.
Just place your cursor in table3Alias, then press Ctrl + Alt + Shift + Left/Right arrow. This changes the parameter order in a function call.
There's also an option for removing one when you press Ctrl + Shift + R
There's also a shortcut to add a format item. You may be able to do what you want with combining these. The exact functionality you ask is not implemented.

System.Windows.Forms.Keys - Lower or Uppercase?

I have been searching around for an answer to this but I can't seem to find anything. Does anyone know if you can determine the letter casing in Keys?
For example:
if (System.Windows.Forms.Keys.A.ToString() == "A")
{
// Upper or Lower?
}
Thanks.
There is no casing, it represents a physical key on your keyboard. Do you see an 'a' and an 'A' on your keyboard?
You can check and see if a Shift key is depressed.
System.Windows.Forms.Keys.A represents the physical key A on your keyboard. It does not have a case. Thus, your question does not make sense.
If you want to check whether the user holds the Shift key on the keybord, there's also System.Windows.Forms.Keys.Shift.
There is no simple mapping between keys and characters. Keyboard layouts can work differently. One example are dead keys. And once you get to IMEs it gets even more complicated. Do not try to duplicate a keyboard layout manually in your application.
If you want to get what character a user entered, handle WM_CHAR, not WM_KEY_DOWN/UP. It's exposed as Control.KeyPress event in winforms.

Converting KBDLLHOOKSTRUCT(.NET) to KeyEvent/Char(Java), JNA

So, basically what i'm doing is using JNA to set a LowLevelKeyboardProc Keyboard hook, everything works perfectly fine, i can get the values exactly like i want them in java, but the problem i get is when trying to convert to chars, it becomes extremely ennoying handling caps locks, SHIFT keys and tons of other things like everything thats not a-z 0-9 on the keyboard, i was wondering if there is a easier way to do the conversion?
heres the details of what I'm getting from the hook every time a key is pressed
http://msdn.microsoft.com/en-us/library/windows/desktop/ms644967(v=VS.85).aspx
, i Figured it might be best to find a way to manually generate a KeyEvent(Not char, since i need something to handle things like F keys, caps lock button, CTRL button etc etc).
Any help i can get is highly appriciated!.
The Abbot project (http://abbot.sf.net) has a system for mapping keycodes to keychars, using predefined keyboard mappings (it generates a wide variety of keystrokes and records the resulting character output). However, Java does not provide a way for "predicting" the resulting character output given a particular key code.
There may be something within the MS libraries.

What are some useful shortcut keys in Visual Studio? [duplicate]

This question already has answers here:
Closed 12 years ago.
Similar Post:
Hidden Features of Visual Studio (2005-2008)?
What are some shortcut keys you know of that make programming faster, easier, or all around more enjoyable?
One of my favorite items is CTRL + . to add an imports/using statement to the top of the code file.
Of course there is Intelli-Sense, it opens automatically or when you hit Ctrl + Space. Select the variable / class / function or whatever it shows you and hit Enter or Tab to insert it.
Code snippets, also provided by the Intelli-Sense list insert code so you do not need to type everything again. Etc. type "prop" and double hit Tab.
Ctrl + K, Ctrl + D to format your total file so it looks cleaner.
#region / #endregion to group your code and allow you to hide the whole region
I like CTRL + K + D, which formats the code in a file.
And although it's not a Visual Studio feature, I highly recommend Resharper.
Couple of my favorites:
CTRL + TAB -- moves you between open code pages
SHIFT + CTRL + F -- allows you to do a search across the entire solution (as sometimes find all references does not work when your solutions get huge)
SHIFT + DELETE -- allows you to remove an entire line from your code without highlighting it.

Visual Studio Extending Ctrl + K, Ctrl + D

I am a bit lazy when it comes to formatting code in Visual Studio and almost rely solely on the magic of Ctrl + K, Ctrl + D (or F depending on what I’m doing). However I loathe having to use my right mouse button to Remove and Sort my using statements and am constantly forgetting.
Assuming that I’m not using Re-Sharper is there any way to extend the Ctrl + K, Ctrl + D keyboard shortcut to format my code and sort my using statements?
Would writing a macro to do both tasks and assigning it the same key combination the only way to do it?
It's not extending the current key combo as such, but there's a Edit.RemoveAndSort command to which you can assign a key binding in Tools -> Options -> Keyboard.
Here's a blog post detailing just that.
From the lack of response I can only assume that I'll need to create a macro and assign it the same keyboard shortcuts... oh well
Sub LazyFormatAndSortUsingMacro()
DTE.ExecuteCommand("Edit.FormatDocument")
DTE.ExecuteCommand("Edit.RemoveAndSort")
End Sub

Categories

Resources