Skip to content

Commit dd51ff0

Browse files
Improve TinyusbConnector::doHandshake
Disable temporarily Drag to Here context menu item
1 parent 2d241f6 commit dd51ff0

File tree

14 files changed

+206
-79
lines changed

14 files changed

+206
-79
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,19 +103,19 @@ to simulate user input.
103103
Using /dev/uinput is straight forward.
104104
- create a new group and add your username to this group
105105
```
106-
# groupadd the_new_group_name
107-
# usermod -aG the_new_group_name username
106+
# groupadd <new-group>
107+
# usermod -aG <new-group> <username>
108108
```
109109
Notice that group membership is re-read on login so You will have log out
110110
and back in for this to take effect.
111111

112112
- Set the permissions
113113
```
114-
# sudo chown root:the_new_group_name /dev/uinput;
114+
# sudo chown root:<new-group> /dev/uinput;
115115
chmod 720 /dev/uinput
116116
```
117117
Permission 720 should be enough, but in some cases you will need to set 777.
118-
Remember these permissions are not permanent, they will be revoke at reboot.
118+
Remember **_these permissions are not permanent, they will be revoke at reboot_**.
119119
Alternatively you can use a device rule file.
120120

121121
### TinyUSB

hid_keyboard_and_mouse/README.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Companion Project for keyboard_and_mouse_input_recorder_and_player
22

33
Build an image for RaspberryPi Pico W, making it into a proxy keyboard and mouse
4-
for keyboard_and_mouse_input_recorder_and_player.
4+
for KeyboardAndMouseRecorderPlayer.
55

66
# How to build
77

@@ -10,13 +10,15 @@ for keyboard_and_mouse_input_recorder_and_player.
1010
# mkdir build
1111
# cd build
1212
# cmake .. -DFAMILY=rp2040 -DPICO_SDK_PATH=/path/to/pico-sdk
13+
-DWIFI_SSID="YOUR_SSID" -DWIFI_PASSWORD="YOUR_PASSWD"\
1314
[
14-
-DWIFI_SSID="YOUR_SSID" -DWIFI_PASSWORD="YOUR_PASSWD"\
1515
-DUDP_SERVER_BUFFER_SIZE=512 -DUDP_SERVER_PORT=4444\
1616
-DLWIP_MODE=background
1717
]
1818
```
1919

20+
Settings inside ```[]``` are optional.
21+
2022
- LWIP_MODE accepts: background or poll. Default: background.
2123

2224
After flashing your Pico W, it should connect to the local network and it will be
@@ -25,4 +27,8 @@ given an ip address. You can check the ip asigned to the UDP server with the com
2527
```
2628
#nmap -sn 192.168.1.*
2729
```
28-
Then repeat the command with Pico w plugged.
30+
Then repeat the command with Pico w plugged.
31+
32+
After flashing the image into Pico W, just set the ip and port into
33+
the interface settings of KeyboardAndMouseRecorderPlayer and it is ready
34+
to be used by KeyboardAndMouseRecorderPlayer.

include/command_parser.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,18 @@ struct CmdType2Bdr<CommandTypes::MouseRightBtn>
8989
};
9090

9191
template<>
92-
struct CmdType2Bdr<CommandTypes::MouseSelection> // this cover drag command too
92+
struct CmdType2Bdr<CommandTypes::MouseSelection>
9393
{
9494
typedef MouseSelectCommand Cmd;
9595
};
9696

97+
98+
template<>
99+
struct CmdType2Bdr<CommandTypes::MouseDrag>
100+
{
101+
typedef MouseDragCommand Cmd;
102+
};
103+
97104
//====================================================================
98105

99106
template<CommandTypes CMDT>

include/enumerations.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ namespace WX
113113
SCREENSHOT_CMD,
114114
START_ROI,
115115
START_DRAGGING,
116+
DRAG_HERE,
116117
CANCEL_NEW_ROI,
117118
DISPLAY_KBOARD,
118119
CLOSE_MENU,

include/input_command.h

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ enum class CommandTypes
6767
Screenshot,// alias for Ctrl
6868
Unicode,
6969
Shortcut,
70+
MouseDrag,
7071
};
7172

7273
enum class CommandInputTypes
@@ -480,7 +481,7 @@ class MouseRightBtnCommand : public InputCommand, public WindowOffset
480481
class MouseSelectCommand : public InputCommand, public WindowOffset
481482
{
482483
public:
483-
MouseSelectCommand(const char* description, int wait, int posX, int posY, int width, int height, const char* windowName);
484+
MouseSelectCommand(const char* description, int wait, uint posX, uint posY, int width, int height, const char* windowName);
484485

485486
virtual ~MouseSelectCommand()=default;
486487

@@ -497,20 +498,32 @@ class MouseSelectCommand : public InputCommand, public WindowOffset
497498
uint m_statusCode;
498499
};
499500

501+
//====================================================================
500502

501-
class MouseSelectCommand2 : public InputCommand, public WindowOffset
503+
class MouseDragCommand : public InputCommand, public WindowOffset
502504
{
503505
public:
504-
MouseSelectCommand2(const char* description, int wait, int endX, int endY, const char* windowName);
506+
MouseDragCommand(const char* description, int wait, int startX, int startY, int endX, int endY, const char* windowName);
507+
MouseDragCommand(const char* description, int wait, int endX, int endY, const char* windowName);
508+
509+
virtual ~MouseDragCommand()=default;
505510

506-
virtual ~MouseSelectCommand2()=default;
511+
static InputCommand* Builder(const char* description, int wait, int startX, int startY, int endX, int endY, const char* windowName)
512+
{
513+
if(startX<0){
514+
return new MouseDragCommand(description, wait, endX, endY, windowName);
515+
}
516+
return new MouseDragCommand(description, wait, startX, startY, endX, endY, windowName);
517+
}
507518

508519
static InputCommand* Builder(const char* description, int wait, int endX, int endY, const char* windowName)
509520
{
510-
return new MouseSelectCommand2(description, wait, endX, endY, windowName);
521+
return new MouseDragCommand(description, wait, endX, endY, windowName);
511522
}
512523

513524
private:
525+
int m_startX;
526+
int m_startY;
514527
int m_endX; //relative to the current window
515528
int m_endY;
516529
uint m_statusCode;

include/mouse_emulator.h

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,30 +39,28 @@ class MouseEmulatorI : public ErrorReporting
3939

4040
void clickLeftBtn();
4141
void clickRightBtn();
42+
4243
/*
4344
* Move mouse to the relative position (dy, dy) in small steps
44-
*
4545
* */
4646
void move(const int dx, const int dy);
4747

4848
/*
4949
* Will move the mouse to the absolute position (absX, absY)
50-
*
5150
* */
5251
virtual void go2Position(const int absX, const int absY, ClientMousePosition getMousePosition);
5352

5453
/*
55-
* Drag the mouse width units on X and height units on Y relative
56-
* to the current mouse position.
54+
* Select rectangle: (absX, absY, width, height)
55+
* Note that width and height can be negative values
5756
* */
58-
void drag(uint width, uint height);
59-
void drag(uint width, uint height, ClientMousePosition getMousePosition);
57+
void select(uint absX, uint absY, uint width, uint height, ClientMousePosition getMousePosition);
6058

6159
/*
62-
* Drag the mouse width units on X and height units on Y from the
63-
* absolute position (absX, absY).
60+
* Drag the mouse from absolute position (startX, startY)
61+
* to absolute position (endX, endY)
6462
* */
65-
void drag(int absX, int absY, uint width, uint height, ClientMousePosition getMousePosition);
63+
void drag(uint startX, uint startY, uint endX, uint endY, ClientMousePosition getMousePosition);
6664

6765
//void scroll(const int x, const int y);
6866

@@ -74,15 +72,14 @@ class MouseEmulatorI : public ErrorReporting
7472
THR=LOW+1,
7573
};
7674

77-
//virtual int getMouseButton(const MOUSE_BUTTONS btn)=0;
78-
7975
/*
8076
* Move the mouse to the relative position (dx, dy)
8177
* */
8278
virtual void setPosition(const int dx, const int dy)=0;
83-
8479
virtual void buttonDown(MOUSE_BUTTONS btn)=0;
8580
virtual void buttonUp(MOUSE_BUTTONS btn)=0;
81+
82+
void moveAbs(const int absX, const int absY, ClientMousePosition getMousePosition);
8683
};
8784

8885
//--------------------------------------------------------------------

include/tinyusb_connector.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ struct TinyusbConnector
3333
static void sendAndWait(void* data, uint dataSize)
3434
{
3535
s_connector->send(data, dataSize);
36-
if(s_connector->receive(500)){
36+
if(s_connector->receive(600)){
3737
std::this_thread::sleep_for(std::chrono::milliseconds(10));
3838
}
3939
}

src/command_parser.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,16 @@ BaseCommand* ParserBuilder(const std::string& line)
100100
case CommandTypes::MouseSelection:
101101
commandPtr=CmdBuilder<CommandTypes::MouseSelection>::Builder(run, description, wait, std::atoi(parts[3]), std::atoi(parts[4]), std::atoi(parts[5]), std::atoi(parts[6]), parts[7]);
102102
break;
103+
case CommandTypes::MouseDrag:
104+
{
105+
if(std::atoi(parts[3])<0){
106+
commandPtr=CmdBuilder<CommandTypes::MouseDrag>::Builder(run, description, wait, std::atoi(parts[5]), std::atoi(parts[6]), parts[7]);
107+
}
108+
else{
109+
commandPtr=CmdBuilder<CommandTypes::MouseDrag>::Builder(run, description, wait, std::atoi(parts[3]), std::atoi(parts[4]), std::atoi(parts[5]), std::atoi(parts[6]), parts[7]);
110+
}
111+
}
112+
break;
103113
case CommandTypes::Shortcut:
104114
commandPtr=CmdBuilder<CommandTypes::Shortcut>::Builder(run, description, wait, parts[3]);
105115
break;

src/input_command.cpp

Lines changed: 55 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -306,8 +306,8 @@ MouseRightBtnCommand::MouseRightBtnCommand(const char* description, int wait, in
306306
}
307307

308308
//====================================================================
309-
310-
MouseSelectCommand::MouseSelectCommand(const char* description, int wait, int posX, int posY, int width, int height, const char* windowName)
309+
//*
310+
MouseSelectCommand::MouseSelectCommand(const char* description, int wait, uint posX, uint posY, int width, int height, const char* windowName)
311311
:InputCommand(description, wait)
312312
, WindowOffset(windowName)
313313
, m_posX(posX)
@@ -321,13 +321,14 @@ MouseSelectCommand::MouseSelectCommand(const char* description, int wait, int po
321321
m_statusCode=ExitCode::OUT_OF_BOUND;
322322
if(isTargetValid(m_posX, m_posY)){
323323
m_statusCode=ExitCode::OK;
324-
s_MouseEmulator->drag(m_absoluteX, m_absoluteY, m_width, m_height, [](int& pX, int& pY){
324+
s_MouseEmulator->select(m_absoluteX, m_absoluteY, m_width, m_height, [](int& pX, int& pY){
325325
wxPoint mousePosition=wxGetMousePosition();
326326
pX=mousePosition.x;
327327
pY=mousePosition.y;
328328
});
329329
}
330330
}
331+
MouseCmdExitPosition::setExitPosition();
331332
};
332333

333334
int ID=static_cast<int>(CommandTypes::MouseSelection);
@@ -337,37 +338,72 @@ MouseSelectCommand::MouseSelectCommand(const char* description, int wait, int po
337338
};
338339
}
339340

340-
MouseSelectCommand2::MouseSelectCommand2(const char* description, int wait, int endX, int endY, const char* windowName)
341+
//====================================================================
342+
343+
MouseDragCommand::MouseDragCommand(const char* description, int wait, int startX, int startY, int endX, int endY, const char* windowName)
344+
:InputCommand(description, wait)
345+
, WindowOffset(windowName)
346+
, m_startX(startX)
347+
, m_startY(startY)
348+
, m_endX(endX)
349+
, m_endY(endY)
350+
{
351+
m_cmd=[this](){
352+
m_statusCode=ExitCode::TARGET_WINDOW_CLOSED;
353+
if(windowExists()){
354+
m_statusCode=ExitCode::OUT_OF_BOUND;
355+
if(isTargetValid(m_startX, m_startY)){
356+
int absStartX=m_absoluteX;
357+
int absStartY=m_absoluteY;
358+
if(isTargetValid(m_endX, m_endY)){
359+
m_statusCode=ExitCode::OK;
360+
int absEndX=m_absoluteX;
361+
int absEndY=m_absoluteY;
362+
363+
s_MouseEmulator->drag(absStartX, absStartY, absEndX, absEndY, [](int& pX, int& pY){
364+
wxPoint mousePosition=wxGetMousePosition();
365+
pX=mousePosition.x;
366+
pY=mousePosition.y;
367+
});
368+
}
369+
}
370+
}
371+
MouseCmdExitPosition::setExitPosition();
372+
};
373+
374+
int ID=static_cast<int>(CommandTypes::MouseDrag);
375+
376+
m_strCmd=[this, ID](){
377+
return ToString2(ID, m_description, m_run, m_startX, m_startY, m_endX, m_endY, m_windowName);
378+
};
379+
}
380+
381+
//--------------------------------------------------------------------
382+
383+
MouseDragCommand::MouseDragCommand(const char* description, int wait, int endX, int endY, const char* windowName)
341384
:InputCommand(description, wait)
342385
, WindowOffset(windowName)
386+
, m_startX(-1)
387+
, m_startY(-1)
343388
, m_endX(endX)
344389
, m_endY(endY)
345390
{
346391
/*
347-
* Notice that if the current mouse changed is not the same as the
392+
* Notice that if the current mouse position is not the same as the
348393
* position of it when the last mouse command exit (it was moved accidently)
349394
* we might get different result. Therefore it would be better to keep
350395
* tract of the mouse position according to the last mouse command executed.
351-
*
352396
* */
353397
m_cmd=[this](){
354398
m_statusCode=ExitCode::TARGET_WINDOW_CLOSED;
355399
if(windowExists()){
356400
m_statusCode=ExitCode::OUT_OF_BOUND;
357401
if(isTargetValid(m_endX, m_endY)){
358402
m_statusCode=ExitCode::OK;
403+
int startX=MouseCmdExitPosition::s_x;
404+
int startY=MouseCmdExitPosition::s_y;
359405

360-
wxPoint mousePosition=wxGetMousePosition();
361-
int startX=mousePosition.x;
362-
int startY=mousePosition.y;
363-
364-
WindowRect rect=getWindowRect(m_windowName.c_str(), true);
365-
int endAbsoluteX=m_endX+rect.m_x;
366-
int endAbsoluteY=m_endY+rect.m_y;
367-
int width=endAbsoluteX-startX;
368-
int height=endAbsoluteY-startY;
369-
370-
s_MouseEmulator->drag(startX, startY, width, height, [](int& pX, int& pY){
406+
s_MouseEmulator->drag(startX, startY, m_absoluteX, m_absoluteY, [](int& pX, int& pY){
371407
wxPoint mousePosition=wxGetMousePosition();
372408
pX=mousePosition.x;
373409
pY=mousePosition.y;
@@ -377,10 +413,10 @@ MouseSelectCommand2::MouseSelectCommand2(const char* description, int wait, int
377413
MouseCmdExitPosition::setExitPosition();
378414
};
379415

380-
int ID=static_cast<int>(CommandTypes::MouseSelection);
416+
int ID=static_cast<int>(CommandTypes::MouseDrag);
381417

382418
m_strCmd=[this, ID](){
383-
return ToString2(ID, m_description, m_run, m_endX, m_endY, m_windowName);
419+
return ToString2(ID, m_description, m_run, -1, -1, m_endX, m_endY, m_windowName);
384420
};
385421
}
386422

0 commit comments

Comments
 (0)