-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
115 lines (107 loc) · 4.81 KB
/
Program.cs
File metadata and controls
115 lines (107 loc) · 4.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
using System;
using System.Collections.Generic;
using WindowsInput;
using WindowsInput.Native;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using static System.Console;
using System.Runtime.InteropServices;
using System.Diagnostics;
namespace VirtualDesktopSwapper
{
class Program
{
[DllImport("User32.dll", CallingConvention = CallingConvention.StdCall, SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool ShowWindow([In] IntPtr hWnd, [In] int nCmdShow);
static void Main(string[] args)
{
Clear();
ShowTitle();
Thread.Sleep(1750);
int[] settings = GetConfig();
IntPtr handle = Process.GetCurrentProcess().MainWindowHandle;
ShowWindow(handle, 6);
RunVirtualDesktopSwapper(settings[0], settings[1]);
}
private static void ShowTitle()
{
WriteLine();
WriteLine("_/ _/ _/ _/_/_/ _/_/_/_/ _/ _/ _/ _/");
WriteLine(" _/ _/ _/ _/ _/ _/ _/ _/ _/_/ _/");
WriteLine(" _/ _/ _/ _/_/_/ _/ _/ _/ _/ _/ _/");
WriteLine(" _/_/ _/ _/ _/ _/ _/ _/ _/_/_/_/ _/");
WriteLine(" _/ _/ _/ _/ _/ _/_/ _/ _/ _/_/_/_/");
WriteLine();
WriteLine(" _/_/ _/_/_/_/ _/_/ _/ _/ _/_/_/_/ _/_/_/ _/_/_/");
WriteLine(" _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/");
WriteLine(" _/ _/ _/_/_/ _/ _/_/ _/ _/ _/ _/_/_/");
WriteLine(" _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/");
WriteLine("_/_/_/ _/_/_/_/ _/_/ _/ _/ _/ _/_/_/ _/");
WriteLine();
WriteLine(" _/_/ _/ _/ _/ _/_/_/ _/_/_/ _/_/_/_/ _/_/_/");
WriteLine(" _/ _/ _/ _/ _/_/ _/ _/ _/ _/ _/ _/ _/");
WriteLine(" _/ _/ _/ _/ _/ _/ _/_/_/ _/_/_/ _/_/_/ _/_/_/");
WriteLine("_/ _/ _/_/ _/_/ _/_/_/_/ _/ _/ _/ _/ _/");
WriteLine(" _/_/ _/ _/ _/ _/ _/ _/ _/_/_/_/ _/ _/");
WriteLine();
}
private static void RunVirtualDesktopSwapper(int _vdCount, int _time)
{
InputSimulator _sim = new InputSimulator();
Write("Press Ctrl + C to quit...");
while (true)
{
for (int i = 0; i < _vdCount; i++)
{
_sim.Keyboard.ModifiedKeyStroke(new[] { VirtualKeyCode.CONTROL, VirtualKeyCode.LWIN }, VirtualKeyCode.LEFT);
}
for (int i = 0; i < _vdCount; i++)
{
Thread.Sleep(_time * 1000);
_sim.Keyboard.ModifiedKeyStroke(new[] { VirtualKeyCode.CONTROL, VirtualKeyCode.LWIN }, VirtualKeyCode.RIGHT);
}
}
}
private static int[] GetConfig()
{
int[] _configSettings = new int[2];
string[] _disposableArray;
string[] file = System.IO.File.ReadAllLines("vds.cfg");
foreach (string line in file)
{
if (!line.StartsWith("#"))
{
_disposableArray = line.Split('=');
try
{
if (_disposableArray[0] == "DESKTOPS")
{
_configSettings[0] = Convert.ToInt32(_disposableArray[1]);
}
else if (_disposableArray[0] == "TIME_BETWEEN_SWAP")
{
_configSettings[1] = Convert.ToInt32(_disposableArray[1]);
}
else
{
WriteLine("ERROR IN CONFIGURATION: Incorrect configuration type. Make sure settings are in a numeric value and there are no extra lines or values in the configuration file");
ReadLine();
}
}
catch (Exception)
{
WriteLine("ERROR IN CONFIGURATION: Wrong input type. Make sure settings are in a numeric value and there are no extra lines or values in the configuration file.");
WriteLine();
Write("Press any key to QUIT...");
ReadLine();
Environment.Exit(1);
}
}
}
return _configSettings;
}
}
}