title: Save System.Windows.Forms.Keys as Setting
body: <p>I'm making a program that uses hotkeys for various things. 
  These hotkeys will be user-settable, and thus it'd be nice if those would be saved on exit.
  Since the amount of keys on a keyboard is pretty large (including the OEM keys and such), I don't feel much warmth towards a huge monstrosity of IF clausules. </p>
  
  <p>I tried using the builtin settings thingamajigg (Properties.Settings.Default etc) But it doesn't seem to save the keys properly. (That or I'm doing something wrong.)</p>
  
  <p>This is the code I'm using for that right now:</p>
  
  <pre><code>// (..some code ommitted) 
  if (comboBox_hotkeys_uploadclipboard_modifier.SelectedText != "" &amp;&amp; comboBox_hotkeys_uploadclipboard_key.SelectedText != "")
  {
      if (comboBox_hotkeys_uploadclipboard_modifier.SelectedText == "None")
          Properties.Settings.Default.hotkeys_uploadclipboard_modifier = 0;
      else
          Properties.Settings.Default.hotkeys_uploadclipboard_modifier = modifierdict[comboBox_hotkeys_uploadclipboard_modifier.SelectedText];
      Properties.Settings.Default.hotkeys_uploadclipboard_key = keydict[comboBox_hotkeys_uploadclipboard_key.SelectedText];
  }
  Properties.Settings.Default.Save();
  return true;
  </code></pre>
  
  <p>And at the beginning of the program i do:</p>
  
  <pre><code>Dictionary&lt;string, uint&gt; modifierdict = new Dictionary&lt;string, uint&gt;();
  Dictionary&lt;string, Keys&gt; keydict = new Dictionary&lt;string, Keys&gt;();
  
  public Form_stuff()
  {
      for (int i = 0; i &lt; Enum.GetNames(typeof(ModifierKeysH)).Length; i++)
      {
          modifierdict.Add(Enum.GetNames(typeof(ModifierKeysH))[i], (uint)Enum.GetValues(typeof(ModifierKeysH)).GetValue(i));
      }
      for (int i = 0; i &lt; Enum.GetNames(typeof(Keys)).Length; i++)
      {
          keydict.Add(Enum.GetNames(typeof(Keys))[i], (Keys)Enum.GetValues(typeof(Keys)).GetValue(i));
      }
  }
  </code></pre>
  
  <p>But, it doesn't seem to actually save the keys, or load them on the next program launch. (yes I have code in place for that part too)</p>
  
  <p>Does anyone know a(n easy) way?</p>
  
  <p>EDIT: </p>
  
  <p>Here's the code i use for setting the hotkeys, without the interop parts etc, those are hosted elsewhere in the code:</p>
  
  <pre><code>    public void SetKeyboardHooks()
      {
          if (!(kbhook == null))
              kbhook.Dispose();
          kbhook = new KeyboardHook();
          //Set clipboard upload hotkey
          kbhook.RegisterHotKey((ModifierKeysH)Properties.Settings.Default.hotkeys_uploadclipboard_modifier, Properties.Settings.Default.hotkeys_uploadclipboard_key);
          kbhook.KeyPressed += new EventHandler&lt;KeyPressedEventArgs&gt;(kbhook_KeyPressed);
      }
  
      void kbhook_KeyPressed(object sender, KeyPressedEventArgs e)
      {
          if (e.Modifier == (ModifierKeysH)Properties.Settings.Default.hotkeys_uploadclipboard_modifier &amp;&amp; e.Key == Properties.Settings.Default.hotkeys_uploadclipboard_key)
          {
              string url = Functions.UploadClipboard();
              Clipboard.SetText(url);
              hificon.ShowBalloonTip(5000, "Upload succesful!", "Uploaded to: " + url,ToolTipIcon.Info);
          }
      }
  </code></pre>
  
  <p>As you can see the code is far from finished. This is just a roadblock here i'm trying to overcome..
  The main thing that doesn't seem to be working is the fact that the hotkeys don't actually get SAVED. settings doesn't seem to like System.Windows.Forms.Keys, and then also skips the ModifierkeysH part, which are saved as uint.</p>