3434#include " wintoastlib.h"
3535using namespace WinToastLib ;
3636
37- std::unordered_set <
37+ std::vector <
3838 std::shared_ptr<std::function<void (mb_shell::js::menu_info_basic_js)>>>
3939 mb_shell::menu_callbacks_js;
4040namespace mb_shell ::js {
@@ -81,8 +81,8 @@ std::function<void()> menu_controller::add_menu_listener(
8181 };
8282 auto ptr =
8383 std::make_shared<std::function<void (menu_info_basic_js)>>(listener_cvt);
84- menu_callbacks_js.insert (ptr);
85- return [ptr]() { menu_callbacks_js. erase (ptr); };
84+ menu_callbacks_js.push_back (ptr);
85+ return [ptr]() { std:: erase (menu_callbacks_js, ptr); };
8686}
8787menu_controller::~menu_controller () {}
8888void menu_item_controller::set_position (int new_index) {
@@ -1237,32 +1237,97 @@ void win32::reg_set_qword(std::string key, std::string name, int64_t value) {
12371237 RegCloseKey (hKey);
12381238}
12391239
1240-
12411240static WORD get_scancode (std::string key) {
12421241 std::transform (key.begin (), key.end (), key.begin (), ::tolower);
12431242
12441243 static const std::unordered_map<std::string, WORD> scancodes = {
1245- {" escape" , 0x01 }, {" 1" , 0x02 }, {" 2" , 0x03 }, {" 3" , 0x04 }, {" 4" , 0x05 },
1246- {" 5" , 0x06 }, {" 6" , 0x07 }, {" 7" , 0x08 }, {" 8" , 0x09 }, {" 9" , 0x0A },
1247- {" 0" , 0x0B }, {" minus" , 0x0C }, {" equal" , 0x0D }, {" backspace" , 0x0E },
1248- {" tab" , 0x0F }, {" q" , 0x10 }, {" w" , 0x11 }, {" e" , 0x12 }, {" r" , 0x13 },
1249- {" t" , 0x14 }, {" y" , 0x15 }, {" u" , 0x16 }, {" i" , 0x17 }, {" o" , 0x18 },
1250- {" p" , 0x19 }, {" bracket_left" , 0x1A }, {" bracket_right" , 0x1B }, {" enter" , 0x1C },
1251- {" ctrl" , 0x1D }, {" a" , 0x1E }, {" s" , 0x1F }, {" d" , 0x20 }, {" f" , 0x21 },
1252- {" g" , 0x22 }, {" h" , 0x23 }, {" j" , 0x24 }, {" k" , 0x25 }, {" l" , 0x26 },
1253- {" semicolon" , 0x27 }, {" quote" , 0x28 }, {" backtick" , 0x29 }, {" shift" , 0x2A },
1254- {" backslash" , 0x2B }, {" z" , 0x2C }, {" x" , 0x2D }, {" c" , 0x2E }, {" v" , 0x2F },
1255- {" b" , 0x30 }, {" n" , 0x31 }, {" m" , 0x32 }, {" comma" , 0x33 }, {" period" , 0x34 },
1256- {" slash" , 0x35 }, {" alt" , 0x38 }, {" space" , 0x39 }, {" capslock" , 0x3A },
1257- {" f1" , 0x3B }, {" f2" , 0x3C }, {" f3" , 0x3D }, {" f4" , 0x3E }, {" f5" , 0x3F },
1258- {" f6" , 0x40 }, {" f7" , 0x41 }, {" f8" , 0x42 }, {" f9" , 0x43 }, {" f10" , 0x44 },
1259- {" numlock" , 0x45 }, {" scrolllock" , 0x46 }, {" home" , 0x47 }, {" up" , 0x48 },
1260- {" pageup" , 0x49 }, {" minus_pad" , 0x4A }, {" left" , 0x4B }, {" center" , 0x4C },
1261- {" right" , 0x4D }, {" plus_pad" , 0x4E }, {" end" , 0x4F }, {" down" , 0x50 },
1262- {" pagedown" , 0x51 }, {" insert" , 0x52 }, {" delete" , 0x53 }, {" f11" , 0x57 },
1263- {" f12" , 0x58 }, {" win" , 0xE05B }, {" context" , 0xE05D }, {" printscreen" , 0xE037 },
1264- {" pause" , 0xE11D45 }
1265- };
1244+ {" escape" , 0x01 },
1245+ {" 1" , 0x02 },
1246+ {" 2" , 0x03 },
1247+ {" 3" , 0x04 },
1248+ {" 4" , 0x05 },
1249+ {" 5" , 0x06 },
1250+ {" 6" , 0x07 },
1251+ {" 7" , 0x08 },
1252+ {" 8" , 0x09 },
1253+ {" 9" , 0x0A },
1254+ {" 0" , 0x0B },
1255+ {" minus" , 0x0C },
1256+ {" equal" , 0x0D },
1257+ {" backspace" , 0x0E },
1258+ {" tab" , 0x0F },
1259+ {" q" , 0x10 },
1260+ {" w" , 0x11 },
1261+ {" e" , 0x12 },
1262+ {" r" , 0x13 },
1263+ {" t" , 0x14 },
1264+ {" y" , 0x15 },
1265+ {" u" , 0x16 },
1266+ {" i" , 0x17 },
1267+ {" o" , 0x18 },
1268+ {" p" , 0x19 },
1269+ {" bracket_left" , 0x1A },
1270+ {" bracket_right" , 0x1B },
1271+ {" enter" , 0x1C },
1272+ {" ctrl" , 0x1D },
1273+ {" a" , 0x1E },
1274+ {" s" , 0x1F },
1275+ {" d" , 0x20 },
1276+ {" f" , 0x21 },
1277+ {" g" , 0x22 },
1278+ {" h" , 0x23 },
1279+ {" j" , 0x24 },
1280+ {" k" , 0x25 },
1281+ {" l" , 0x26 },
1282+ {" semicolon" , 0x27 },
1283+ {" quote" , 0x28 },
1284+ {" backtick" , 0x29 },
1285+ {" shift" , 0x2A },
1286+ {" backslash" , 0x2B },
1287+ {" z" , 0x2C },
1288+ {" x" , 0x2D },
1289+ {" c" , 0x2E },
1290+ {" v" , 0x2F },
1291+ {" b" , 0x30 },
1292+ {" n" , 0x31 },
1293+ {" m" , 0x32 },
1294+ {" comma" , 0x33 },
1295+ {" period" , 0x34 },
1296+ {" slash" , 0x35 },
1297+ {" alt" , 0x38 },
1298+ {" space" , 0x39 },
1299+ {" capslock" , 0x3A },
1300+ {" f1" , 0x3B },
1301+ {" f2" , 0x3C },
1302+ {" f3" , 0x3D },
1303+ {" f4" , 0x3E },
1304+ {" f5" , 0x3F },
1305+ {" f6" , 0x40 },
1306+ {" f7" , 0x41 },
1307+ {" f8" , 0x42 },
1308+ {" f9" , 0x43 },
1309+ {" f10" , 0x44 },
1310+ {" numlock" , 0x45 },
1311+ {" scrolllock" , 0x46 },
1312+ {" home" , 0x47 },
1313+ {" up" , 0x48 },
1314+ {" pageup" , 0x49 },
1315+ {" minus_pad" , 0x4A },
1316+ {" left" , 0x4B },
1317+ {" center" , 0x4C },
1318+ {" right" , 0x4D },
1319+ {" plus_pad" , 0x4E },
1320+ {" end" , 0x4F },
1321+ {" down" , 0x50 },
1322+ {" pagedown" , 0x51 },
1323+ {" insert" , 0x52 },
1324+ {" delete" , 0x53 },
1325+ {" f11" , 0x57 },
1326+ {" f12" , 0x58 },
1327+ {" win" , 0xE05B },
1328+ {" context" , 0xE05D },
1329+ {" printscreen" , 0xE037 },
1330+ {" pause" , 0xE11D45 }};
12661331
12671332 auto it = scancodes.find (key);
12681333 if (it != scancodes.end ()) {
@@ -1277,22 +1342,23 @@ bool win32::is_key_down(std::string key) {
12771342
12781343 WORD scancode = get_scancode (key_lower);
12791344 if (scancode != 0 ) {
1280- SHORT state = GetAsyncKeyState (MapVirtualKeyW (scancode & 0xFF , MAPVK_VSC_TO_VK));
1345+ SHORT state =
1346+ GetAsyncKeyState (MapVirtualKeyW (scancode & 0xFF , MAPVK_VSC_TO_VK));
12811347 return (state & 0x8000 ) != 0 ;
12821348 }
12831349
12841350 return false ;
12851351}
12861352
1287-
12881353static bool is_extended_key (WORD scancode) {
12891354 return (scancode & 0xFF00 ) == 0xE000 || (scancode & 0xFF0000 ) == 0xE10000 ;
12901355}
12911356
12921357void win32::simulate_hotkeys (std::vector<std::string> keys) {
1293- if (keys.empty ()) return ;
1358+ if (keys.empty ())
1359+ return ;
12941360
1295- for (const auto & key : keys) {
1361+ for (const auto & key : keys) {
12961362 simulate_key_down (key);
12971363 }
12981364 for (auto it = keys.rbegin (); it != keys.rend (); ++it) {
@@ -1307,7 +1373,8 @@ void win32::simulate_key_press(std::string key) {
13071373
13081374void win32::simulate_key_down (std::string key) {
13091375 WORD sc = get_scancode (key);
1310- if (sc == 0 ) return ;
1376+ if (sc == 0 )
1377+ return ;
13111378
13121379 INPUT input = {0 };
13131380 input.type = INPUT_KEYBOARD;
@@ -1323,7 +1390,8 @@ void win32::simulate_key_down(std::string key) {
13231390
13241391void win32::simulate_key_up (std::string key) {
13251392 WORD sc = get_scancode (key);
1326- if (sc == 0 ) return ;
1393+ if (sc == 0 )
1394+ return ;
13271395
13281396 INPUT input = {0 };
13291397 input.type = INPUT_KEYBOARD;
@@ -1342,7 +1410,7 @@ void win32::simulate_text_input(std::string text) {
13421410
13431411 for (wchar_t c : wtext) {
13441412 INPUT input[2 ] = {0 };
1345-
1413+
13461414 input[0 ].type = INPUT_KEYBOARD;
13471415 input[0 ].ki .wScan = c;
13481416 input[0 ].ki .dwFlags = KEYEVENTF_UNICODE;
@@ -1364,7 +1432,8 @@ void win32::simulate_mouse_move(int x, int y) {
13641432 SendInput (1 , &input, sizeof (INPUT));
13651433}
13661434
1367- static void get_mouse_flags (std::string button, bool down, DWORD& flags, DWORD& data) {
1435+ static void get_mouse_flags (std::string button, bool down, DWORD &flags,
1436+ DWORD &data) {
13681437 std::transform (button.begin (), button.end (), button.begin (), ::tolower);
13691438 flags = 0 ;
13701439 data = 0 ;
@@ -1392,8 +1461,9 @@ void win32::simulate_mouse_click(std::string button) {
13921461void win32::simulate_mouse_down (std::string button) {
13931462 DWORD flags, data;
13941463 get_mouse_flags (button, true , flags, data);
1395-
1396- if (flags == 0 ) return ;
1464+
1465+ if (flags == 0 )
1466+ return ;
13971467
13981468 INPUT input = {0 };
13991469 input.type = INPUT_MOUSE;
@@ -1406,7 +1476,8 @@ void win32::simulate_mouse_up(std::string button) {
14061476 DWORD flags, data;
14071477 get_mouse_flags (button, false , flags, data);
14081478
1409- if (flags == 0 ) return ;
1479+ if (flags == 0 )
1480+ return ;
14101481
14111482 INPUT input = {0 };
14121483 input.type = INPUT_MOUSE;
0 commit comments