Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- SHsuperCM's C# Code Bank
- This file contains some code for the C# language that
- anyone can use and not credit, and is organized using
- a seperate C# program which is private.
- */
- $utility start
- $$name start
- M - Async Key Down/Press
- $$name end
- $$information start
- These 2 Methods will tell you if a key is being held or being pressed.
- GetAsyncKeyDown(Keys key) returns a boolean stating
- if "key" is down.
- GetAsyncKeyPress(Keys key) returns a boolean stating
- if "key" is down and was not down before.
- $$information end
- $$code start
- [DllImport("user32.dll")]
- private static extern short GetAsyncKeyState(int vKey);
- private static bool GetAsyncKeyDown(Keys key) { return GetAsyncKeyState((int)key) != 0; }
- private static List<Keys> prevKeysDown = new List<Keys>();
- private static bool GetAsyncKeyPress(Keys key)
- {
- bool returning = true;
- foreach (Keys prevKey in prevKeysDown){
- if (key == prevKey) returning = false;
- }
- if (GetAsyncKeyDown(key) && returning == true) prevKeysDown.Add(key);
- if (!GetAsyncKeyDown(key)) returning = false;
- for (int i = 0; i < prevKeysDown.Count(); i++){
- if (!GetAsyncKeyDown(prevKeysDown[i])) prevKeysDown.RemoveAt(i);
- }
- return returning;
- }
- $$code end
- $utility end
- $utility start
- $$name start
- M - Stream from String
- $$name end
- $$information start
- Can be used to read a string line by line using a StreamReader.ReadLine().
- StreamFromString(string strIN) returning
- a Stream from "strIN".
- $$information end
- $$code start
- public static Stream StreamFromString(string strIN)
- {
- MemoryStream stream = new MemoryStream();
- StreamWriter writer = new StreamWriter(stream);
- writer.Write(strIN);
- writer.Flush();
- stream.Position = 0;
- return stream;
- }
- $$code end
- $utility end
- $utility start
- $$name start
- M - Stream from URL
- $$name end
- $$information start
- Creates a Stream from "urlIN"'s source code, also reads raw pastebins posts.
- StreamFromURL(string urlIN) returning
- a Stream from "urlIN"'s URL.
- $$information end
- $$code start
- public static Stream StreamFromURL(string urlIN)
- {
- return (new WebClient()).OpenRead(urlIN);
- }
- $$code end
- $utility end
- $utility start
- $$name start
- M - Get Cut Part
- $$name end
- $$information start
- Get the string between 2 strings inside a big string.
- string GetCutPart(string inputIN, string startIN, string endIN, bool keepStartAndEndIN) returning
- a string that is inside "inputIN" and between "startIN" and "endIN",
- if "keepStartAndEndIN" is true, it will keep "startIN" and "endIN" on the returned value.
- $$information end
- $$code start
- public static string GetCutPart(string inputIN, string startIN, string endIN, bool keepStartAndEndIN)
- {
- string returning = "";
- string read = "";
- bool collecting = false;
- foreach (char chr in inputIN)
- if (collecting)
- {
- returning += chr;
- if (returning.EndsWith(endIN))
- {
- return (keepStartAndEndIN ? (startIN + returning) : returning.Replace(endIN, ""));
- }
- }
- else
- {
- read += chr;
- if (read.EndsWith(startIN))
- collecting = true;
- }
- return null;
- }
- $$code end
- $utility end
- $utility start
- $$name start
- L - Open URL in browser
- $$name end
- $$information start
- Open URL inside the default browser.
- (chrome/internetexplorer/firefox...)
- $$information end
- $$code start
- Process.Start(string URL);
- $$code end
- $utility end
- $utility start
- $$name start
- L - Set the ClipBoard text
- $$name end
- $$information start
- Set the text that will be in ctrl-v.
- $$information end
- $$code start
- Clipboard.SetText(string Text);
- $$code end
- $utility end
- $utility start
- $$name start
- M - StreamReader From File Path
- $$name end
- $$information start
- Gets a StreamReader from the contents of the file in "pathIN".
- StreamReaderFromFile(string pathIN) returns
- StreamReader generated from the contents of the file in "pathIN",
- will return null if either the file does not exist or there was a problem reading it.
- $$information end
- $$code start
- public static StreamReader StreamReaderFromFile(string pathIN)
- {
- if (File.Exists(pathIN))
- try
- {
- return new StreamReader(pathIN);
- }
- catch { return null; }
- else
- return null;
- }
- $$code end
- $utility end
- $utility start
- $$name start
- M - Search in list of strings
- $$name end
- $$information start
- Searching in a list of strings.
- List<string> Search(List<string> input, string compared)
- returns a list of strings from input that contain the compared strings.
- $$information end
- $$code start
- public static List<string> Search(List<string> input, string compared)
- {
- List<string> result = new List<string>();
- foreach (string item in input)
- if (item.Contains(compared))
- result.Add(item);
- return result;
- }
- $$code end
- $utility end
- $utility start
- $$name start
- M - Is Form Active
- $$name end
- $$information start
- Determines if the form of which the method is located at is active.
- Active forms are the ones windows focuses on when choosing where user input will go.
- $$information end
- $$code start
- public bool IsActive() {
- return System.Windows.Forms.Form.ActiveForm == this;
- }
- $$code end
- $utility end
Add Comment
Please, Sign In to add comment